-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README, pip requirements and update command-line interface
- Loading branch information
1 parent
86918b2
commit c8a6c02
Showing
7 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
venv/ | ||
# Flask static file cache | ||
flaskapp/static/.webassets-cache/ | ||
flaskapp/static/public/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Starter flask app | ||
|
||
This repo serves as the base setup for developing your flask application, with some of the best practices and easy-to-scale code structure. | ||
|
||
|
||
### Features | ||
* Create views with re-usable Jinja templates | ||
* CSS & JS bundles defined to enable loading only the required files page-wise | ||
* Easy to configure/enable the following: | ||
* MongoDB connection and querying | ||
* Uploading & downloading of static files | ||
* Gzip compression | ||
* CSS, JS minification | ||
|
||
**Note** : Tested with Python 3.6 | ||
|
||
|
||
## Setting up project | ||
|
||
1. Clone the repo | ||
|
||
2. Create virtual environment for the project and install pip dependencies | ||
```bash | ||
cd starter_flask_app | ||
virtualenv -p python3 venv | ||
# Source the virtual env | ||
# zsh/fish users need to use activate.zsh/activate.fish files instead | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
``` | ||
|
||
|
||
## Running the server | ||
|
||
```bash | ||
python run.py | ||
``` | ||
|
||
Supported arguments: | ||
* ```--host``` : To set the app host (defaults to 0.0.0.0) | ||
* ```--port``` : To set the app port (defaults to 5000) | ||
* ```--debug``` : Pass this flag to enable debugging | ||
|
||
Now open ```http://localhost:5000``` in your browser to view the app. | ||
|
||
|
||
## Developing your app from the base code | ||
|
||
* Enabling mongo: | ||
* Set the appropriate constants in ```flaskapp/config.py``` | ||
* Uncomment the mentioned line in ```flaskapp/app.py``` | ||
* Enabling static file downloading: | ||
* Set the variable ```DOWNLOADS_DIR``` in ```flaskapp/config.py``` | ||
* Uncomment the mentioned function in ```flaskapp/app.py``` | ||
* Modify the route in this function as appropriate. | ||
* Define templates for your pages in ```flaskapp/templates/``` dir. | ||
See ```home.html``` for reference which inherits the basic structure from ```layout.html``` | ||
and just defines the required parts. | ||
* Define route for the pages in ```flaskapp/routes/view_routes.py``` | ||
* Define API related routes in ```flaskapp/routes/api_routes.py``` | ||
* Add the CSS & JS files in ```flaskapp/static/``` in appropriate subdir. | ||
Then, define the suitable bundle page-wise in ```flaskapp/assets.py```. | ||
Refer the existing bundles in the file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
# Used to set : app.config['SEND_FILE_MAX_AGE_DEFAULT'] | ||
STATIC_FILE_MAX_AGE = 3600 * 24 * 7 | ||
STATIC_FILE_MAX_AGE = 3600 * 24 * 7 # 1 week | ||
|
||
# MongoDB variables | ||
MONGO_HOST = "localhost" | ||
MONGO_PORT = "27017" | ||
MONGO_NAME = "dbname" | ||
MONGO_USER = "" | ||
MONGO_PASS = "" | ||
|
||
# Directory for uploading files to server | ||
UPLOADS_DIR = "uploads/" | ||
|
||
# Directory for downloading files from server | ||
DOWNLOADS_DIR = "/data_files" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
UPLOADS_FOLDER = "uploads/" | ||
DATA_FILE_DIR = "/data_files" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
certifi==2019.9.11 | ||
chardet==3.0.4 | ||
Click==7.0 | ||
cssmin==0.2.0 | ||
Flask==1.1.1 | ||
Flask-Assets==0.12 | ||
Flask-Compress==1.4.0 | ||
Flask-PyMongo==2.3.0 | ||
get==2019.4.13 | ||
idna==2.8 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.10.3 | ||
jsmin==2.2.2 | ||
MarkupSafe==1.1.1 | ||
post==2019.4.13 | ||
public==2019.4.13 | ||
pymongo==3.9.0 | ||
query-string==2019.4.13 | ||
request==2019.4.13 | ||
requests==2.22.0 | ||
urllib3==1.25.6 | ||
webassets==0.12.1 | ||
Werkzeug==0.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters