Write notes to use Flask for the first time in business.
from flask import Flask,render_template,request
#from module import class 1,Class 2,Class 3...
#Use request class
from flask import Flask, render_template, request
name = request.args.get("name")
#Use request class and prepare method when received by POST
from flask import Flask, render_template, request
@app.route("/post", methods = ["post"])
def post():
name = request.form["name"]
#For lists, use getlist
names = request.form.getlist("names")
#Controller side
render_template("index.html", name = name)
#Template side
<div>{{name}}</div>
#Template side
{% if name == "tokyo" %}
<div>capital{{name}}</div>
{% elif name %}
<div>{{name}}</div>
{% else %}
<div>Anonymous</div>
{% endif %}
#Template side
{% for city in cities %}
<div>{{city}}</div>
{% endfor %}
# GET
@app.route("/get")
def get():
# POST
@app.route("/post", methods = ["post"])
def post():
pip install -r requirements.txt
The contents of requirements.txt look like this
Flask==1.1.1
SQLAlchemy==1.3.10
・
・
・
Add more modules you want to install
Continue to Part 2
Recommended Posts