Use Flask + Python3.6+mysql to write a simple comment module. After the input is submitted, it appears on the page.
Send and accept data from a comment box
falsk
before returning to the first page of the function, add the methods
attribute.
@app.route("/", methods=["GET", "POST"])
Two methods of receiving data are temporarily saved and displayed on the Web page.
in-memory storage
The main program is as follows and reload
is initialized whenever the program is in process comments
.
fromFlaskImportFlask, redirect, Render_template, request, Url_forapp = Flask (__name__) app.config["DEBUG"] =Truecomments = []@app. Route ("/", methods=["GET", "POST"]) def index(): ifRequest.method = ="GET":returnRender_template ("Main_page.html", comments=comments) Comments.append (request.form["Contents"])returnRedirect (Url_for (' index '))
Persistent write to database Python declaration
First, declare a database management tool statement in Flask SQLAlchemy
as follows:
fromFlask_sqlalchemyImportSqlalchemysqlalchemy_database_uri ="Mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}". Format (username="Aubucuo", password=' Database password ', hostname="Database Address", databasename="Aubucuo$comments",) app.config["Sqlalchemy_database_uri"] = sqlalchemy_database_uriapp.config["Sqlalchemy_pool_recycle"] =299app.config["Sqlalchemy_track_modifications"] =Falsedb = SQLAlchemy (APP) comments = [] class Comment(db. Model):__tablename__ ="Comments"ID = db. Column (db. Integer, primary_key=True) content = db. Column (db. String (4096))
DB execution app
, instantiate link to database.
Command line CREATE table for database
3.6fromimport dbdb.create_all()
After executing the above code, the table is created.
Database commands
The database commands are all at the ;
end!
Some common commands about git
git status
View current Code Status
git add filename/文件夹名
Update current file
git commit -m ‘说明文字‘
Add descriptive text to git for this time
git commit -am "说明文字"
Update all the changed files and add this note
git log
View the update log
git diff
See where changes are taking place
?
Use Flask + Python3.6+mysql to write a simple comment module.