Skip to content

Commit fab2b34

Browse files
committed
init draft
1 parent 2b2d930 commit fab2b34

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
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+

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
This is the config file which include all ccnfiguation info here
2+
This is the config file which includes all ccnfiguation info here
33
'''
44

55
_DB_CONF = {

requirement.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
simplejson
22
pymysql
3-
Flask==0.10.1
3+
Flask
44
flask-cors
5-
gunicorn==19.6.0
5+
gunicorn==19.7.1

0 commit comments

Comments
 (0)