You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- INTERNATIONALIZATION with functions like get_locale() and get_timezone() (flask-babel optional) based on :
39
-
current_user locale and current_user timezone
39
+
current_user locale and current_user timezone
40
40
or global current_language and global timezone
41
41
or browser language and locale timezone
42
42
- Helpers (include decorators like SSL required, threaded function, Datetime and timezone utils, datetime format filter, random populate data, Random token generator)
43
-
- Maintenance/coming-soon, flash-message page
43
+
- Maintenance/coming-soon, flash-message page
44
44
- Error handlers : 404 (path not found),
45
-
500 (server error),
46
-
403 (forbidden page or invalid csrf token form),
47
-
400 (Bad request, the syntax of the request entity is not correct),
45
+
500 (server error),
46
+
403 (forbidden page or invalid csrf token form),
47
+
400 (Bad request, the syntax of the request entity is not correct),
48
48
422 (Unprocessable Entity : the request is syntactically correct but his contained instructions is
49
49
semantically erroneous so it was unable to process )
50
50
@@ -62,77 +62,42 @@ Python Flask WEB API DEMO
62
62
- `python run.py` -> http://server_ip:5000
63
63
64
64
#### Use it with configuration environment variable :
65
-
- `export FLASK_CONFIG=development`
66
-
or on Windows systems shell script `set FLASK_CONFIG=development`
67
-
- `export FLASK_APP=run.py`
65
+
- `export FLASK_CONFIG=production`
66
+
or on Windows systems shell script `set FLASK_CONFIG=production`
67
+
- `export FLASK_APP=run.py`
68
68
or on Windows systems `set FLASK_APP=run.py`
69
69
- `flask run`
70
70
71
+
##### Customize config:
72
+
- check the `config.py`file or your secret config `instance/config.py` file
71
73
72
-
#### PRODUCTION CONFIG with GUNICORN : Use it for production with GUNICORN Upstart script and NGINX config from utils directory :
73
-
74
-
- set environment to production with `export FLASK_CONFIG=development`
75
-
or on Windows systems shell script `set FLASK_CONFIG=development`
76
-
- active your Python virtual environment
77
-
- GUNICORN : on shell command type `gunicorn --bind 0.0.0.0:5000 run:app`
78
-
'run' is the name of your main application file 'run.py' which serve as the entry point for your application
79
-
'app' is here the name of your defined application in app/__init__.py
80
-
- If you visit your server's domain name or IP address with :5000 appended to the end in your web browser, you should see the homepage of your application
81
-
- Create an Upstart script which will allow server to automatically start Gunicorn and serve our Flask application whenever the server boots :
or customize Upstart script file (edit example in file 'myproject_gunicorn.conf' in utils directory and replace 'myproject' paths by your project path) (replace user keyword by your chosen server user name ) and place it in /etc/init/myproject_gunicorn.conf
84
-
- then type `sudo start myproject_gunicorn` (replace myproject with your application folder name)
85
-
- After editing a code, you can refresh app by typing `sudo service myproject_gunicorn restart`
86
-
- NOTE : with our Gunicorn config upstart script file, you can generate Python and Gunicorn error logs file and access logs file in your project folder 'myproject/logs'
87
-
88
-
- NGINX: then create a new server block configuration file in Nginx's sites-available directory.
89
-
`sudo nano /etc/nginx/sites-available/myproject`
90
-
- then customize it : see example in file 'myproject_nginx.txt' in utils directory
91
-
- Then enable the Nginx server block configuration, link the file to the sites-enabled directory:
#### About python virtual environment : how to manage it in local project directory:
138
103
@@ -156,7 +121,7 @@ Python Flask WEB API DEMO
156
121
# Activate this environment for your current shell session
157
122
`workon [<name>]`
158
123
or `source my_project/bin/activate`
159
-
or on Windows go in the Scripts path folder `cd my_project/env/env1/Scripts` then `activate`
124
+
or on Windows go in the Scripts path folder `cd my_project/env/libs1/Scripts` then `activate`
160
125
161
126
- WARNING ON WINDOWS SYSTEMS : Some paths within the virtualenv are slightly different on Windows: scripts and executables on Windows go in ENV\Scripts\ instead of ENV/bin/ and libraries go in ENV\Lib\ rather than ENV/lib/.
162
127
on Windows systems, the equivalent activate script is by opening active shell in the Scripts folder (Based on your active shell (CMD.exe or Powershell.exe), Windows will use either activate.bat or activate.ps1)
@@ -169,75 +134,101 @@ Python Flask WEB API DEMO
169
134
# Remove a virtual environment
170
135
`rmvirtualenv [<name>]`
171
136
137
+
##### To install a new package and save it on requirement file:
138
+
`python -m pip install <new_package> && pip list > requirements.txt && pip list --format=freeze > requirements-pip2.txt`
##### Extra configs for your server production environment : ./utils
152
+
with nginx, gunicorn, tornado and supervisor (upstart or supervisord) configuration files
180
153
181
-
> <!DOCTYPE html>
182
-
> {% set bootstrap_version = '3.3.4' %}
183
-
> {% set jquery_version = '2.1.3' %}
184
-
> {% set modernizer_version = '2.8.3' %}
185
-
> {% set bootswatch_version = '3.3.2' %}
186
-
> {% set bootswatch_theme = 'slate' %}
154
+
#### PRODUCTION CONFIG with GUNICORN : Use it for production with GUNICORN Upstart script and NGINX config from utils directory :
187
155
188
-
In case you don't like the "slate" theme, you can chose a nice theme from http://bootswatch.com/ and just replace the theme name
156
+
- set environment to production with `export FLASK_CONFIG=production`
157
+
or on Windows systems shell script `set FLASK_CONFIG=production`
158
+
- active your Python virtual environment
159
+
- GUNICORN : on shell command type `gunicorn --bind 0.0.0.0:5000 run:app`
160
+
'run' is the name of your main application file 'run.py' which serve as the entry point for your application
161
+
'app' is here the name of your defined application in app/__init__.py
162
+
- If you visit your server's domain name or IP address with :5000 appended to the end in your web browser, you should see the homepage of your application
163
+
- Create an Upstart script which will allow server to automatically start Gunicorn and serve our Flask application whenever the server boots :
or customize Upstart script file (edit example in file 'myproject_gunicorn.conf' in utils directory and replace 'myproject' paths by your project path) (replace user keyword by your chosen server user name ) and place it in /etc/init/myproject_gunicorn.conf
166
+
- then type `sudo start myproject_gunicorn` (replace myproject with your application folder name)
167
+
- After editing a code, you can refresh app by typing `sudo service myproject_gunicorn restart`
168
+
- NOTE : with our Gunicorn config upstart script file, you can generate Python and Gunicorn error logs file and access logs file in your project folder 'myproject/logs'
189
169
190
-
##### Customize database :
191
-
# Edit sql file in data folder
170
+
- NGINX: then create a new server block configuration file in Nginx's sites-available directory.
171
+
`sudo nano /etc/nginx/sites-available/myproject`
172
+
- then customize it : see example in file 'myproject_nginx.txt' in utils directory
173
+
- Then enable the Nginx server block configuration, link the file to the sites-enabled directory:
0 commit comments