티스토리 뷰
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
import mysql.connector
basedir = os.path.dirname(os.path.abspath(__file__))
db = {
'user' : 'root',
'password' : 'root',
'host' : 'localhost',
'port' : '3306',
'database' : 'mariadb'
}
mysql_con = None
#------------------------------------------------------#
def query_executor(cursor):
sql = "select * from food"
cursor.execute(sql,)
#------------------------------------------------------#
if __name__ == "__main__":
print('test')
try:
mysql_con = mysql.connector.connect(host='localhost', port='3306', database='mariadb', user='root', password='root')
mysql_cursor = mysql_con.cursor(dictionary=True)
query_executor(mysql_cursor)
for row in mysql_cursor:
print('price is: '+str(row['price']))
mysql_cursor.close()
except Exception as e:
print(e.message)
finally:
if mysql_con is not None:
mysql_con.close()
|
cs |
app.py - SOUP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
from flask import Flask, render_template, request
from service.calculator_service import CalculatorService
from config import basedir
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/calc', methods=["post"])
def calc():
num1 = request.form['num1']
num2 = request.form['num2']
opcode = request.form['opcode']
calc = CalculatorService()
result = calc.calc(num1, num2, opcode)
render_params = {}
render_params['result'] = result
return render_template('index.html', **render_params)
if __name__ == '__main__':
print(f'******* {basedir} ')
app.run()
|
cs |
app.py - RESTful
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Rest(Resource):
def get(self):
return {'rest': 'Good !'}
api.add_resource(Rest, '/')
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=8080)
|
cs |
'5. 파이썬' 카테고리의 다른 글
Flask config.py (0) | 2020.10.07 |
---|---|
파이썬/퍼셉트론-아달린/하마/ perceptron.py (0) | 2020.10.05 |
머신러닝/--/하마/ 타이타닉 컬럼 (Feature) (0) | 2020.09.23 |
선형대수의 데이터 유형과 axis 이해 (0) | 2020.09.22 |
파이참(Pycharm) 프로젝트 시작하기 - Hello World ! (0) | 2020.09.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Django
- React
- COLAB
- SQLAlchemy
- Git
- Python
- SpringBoot
- database
- ERD
- Mlearn
- Oracle
- jQuery
- nodejs
- Eclipse
- docker
- mariadb
- JPA
- Mongo
- FLASK
- AWS
- maven
- vscode
- Algorithm
- intellij
- JUnit
- terms
- springMVC
- KAFKA
- Java
- tensorflow
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함