-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
51 lines (41 loc) · 1.49 KB
/
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
from flask import Flask,render_template
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import func
import json
from flask_bootstrap import Bootstrap5
from flask import request
app=Flask(__name__)
bootstrap=Bootstrap5(app)
@app.route('/')
def hello_world():
return "<p>Hello</p>"
DB_URI='mysql+pymysql://root:[email protected]:3306/blog'
app.config['SQLALCHEMY_DATABASE_URI']=DB_URI
app.config['SQLALCHEMY_ECHO']=True
app.config['DEBUG'] = True
db=SQLAlchemy(app)
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title =db.Column(db.String(100),nullable=False)
content =db.Column(db.String(100),nullable=False)
sectionId= db.Column(db.Integer, nullable=False)
type= db.Column(db.Integer, nullable=False)
updateTime =db.Column(db.DateTime(timezone=False),server_default=func.now())
createTime =db.Column(db.DateTime(timezone=False),server_default=func.now())
poster= db.Column(db.Integer, nullable=False)
def __repr__(self):
return f'<Post {self.title}>'
@app.route('/index')
def index():
rows=Post.query.all()
return render_template("main.html", data=rows)
@app.route('/post',methods=['POST'])
def post():
if request.method=='POST':
data = request.get_json()
title = data['title']
content =data['content']
Poster=Post(title=title,content=content,sectionId=1,type=1,poster=1)
db.session.add(Poster)
db.session.commit()
return 'hello'