File tree Expand file tree Collapse file tree 3 files changed +73
-4
lines changed Expand file tree Collapse file tree 3 files changed +73
-4
lines changed Original file line number Diff line number Diff line change 1
- # python-flask-mysql
1
+ # python-flask-mysql
2
+ This is just a simple demo how to develop a webservice using python, flask and mysql. `` pymysql `` python mysql driver is used here.
3
+
4
+ ```
5
+ $ python -V
6
+ Python 3.6.0
7
+ ```
8
+
9
+ ### Install required python packages
10
+
11
+ ```
12
+ $ pip install -r requirements.txt
13
+ ```
14
+
15
+ ### Config and start webservice
16
+
17
+ ##### Configure MySQL settings
18
+
19
+ In `` config.py `` file, fill in your real MySQL connection settings
20
+
21
+ ```
22
+ _DB_CONF = {
23
+ 'host':'<YOUR-MYSQL-HOST>',
24
+ 'port':3306,
25
+ 'user':'<YOUR-MYSQL-USERNAME>',
26
+ 'passwd':'<YOUR-MYSQL-PASSWORD>',
27
+ 'db':'<YOUR-MYSQL-DATABASE>'
28
+ }
29
+ ```
30
+
31
+ ##### Change MySQL query
32
+
33
+ In `` main.py `` file, put your real mysql select query here
34
+
35
+ ```
36
+ sql="<PUT YOUR MySQL QUERY HERE>"
37
+ ```
38
+
39
+
40
+ ##### Start Webservoce
41
+
42
+ ```
43
+ $ gunicorn -b :8080 main:app
44
+ ```
45
+
46
+ ### Test your webservice using curl
47
+
48
+ ```
49
+ curl http://localhost:8080/test
50
+ ```
51
+
52
+ You can also test your webservice remotely
53
+
54
+ ```
55
+ curl http://<SERVER-IP>:8080/test
56
+ ```
57
+
58
+ If you have trouble with 'Access-Control-Allow-Origin' error when making cross-origin ajax call, add the following
59
+
60
+ ```
61
+ from flask_cors import CORS
62
+
63
+ app = Flask(__name__)
64
+
65
+ """
66
+ CORS function is to avoid No 'Access-Control-Allow-Origin' error
67
+ """
68
+ CORS(app)
69
+ ```
70
+
Original file line number Diff line number Diff line change 1
1
'''
2
- This is the config file which include all ccnfiguation info here
2
+ This is the config file which includes all ccnfiguation info here
3
3
'''
4
4
5
5
_DB_CONF = {
Original file line number Diff line number Diff line change 1
1
simplejson
2
2
pymysql
3
- Flask==0.10.1
3
+ Flask
4
4
flask-cors
5
- gunicorn==19.6.0
5
+ gunicorn==19.7.1
You can’t perform that action at this time.
0 commit comments