Notes on Flask

I'm sorry to say that there is a memorial element.

Transcendence basic

Write a template-like program below. The directory structure is

Qiita/ ├templates │ ├index.html │ └posted.html └app.py

app.py


from flask import Flask, render_template, request

app = Flask(__name__)
##Up to this point is like a template

@app.route('/home')
def home():
    return render_template('index.html')

@app.route('/post',methods=['POST','GET'])
def post():
    if request.method == 'POST':
        all = request.form
        return render_template('check.html',name=name,val = val)

if __name__ == "__main__":
  #You can also set the port to open here.
    app.run(host='0.0.0.0',port=5000,debug=True)

Now I would like to explain this program.

Commentary

python


@app.route('/home')

Is this checking if you accessed http://0.0.0.0:5000/home? It is a thing. After this

python


return render_template('index.html')

Then run templates / index.html.

python


@app.route('/post',methods=['POST','GET'])
def post():
    if request.method == 'POST':
        all = request.form
        return render_template('posted.html',data=all)

Then, if it is ** POST ** or ** GET ** method, it will be processed. Also, request.form receives POSTed data in dict type. For example, if name =" tsukkey " is entered, enter request.form ['name'] to refer to tsukkey. With data = all inrender_template (), it feels like sending the POSTed value to posted.html. As for the html file, I will not raise it because it is troublesome, but if you write an if statement or something by enclosing it in {%%}, it is basically quite good.

Recommended Posts

Notes on Flask
Celery notes on Django
Notes on installing PycURL
jsonschema validation on flask
Notes on using Alembic
Notes on SciPy.linalg functions
Notes on tf.function and Tracing
Notes on installing dlib on mac
Notes on python's sqlite3 module
Notes on * args and ** kargs
[Django] Notes on using django-debug-toolbar
Notes on pyenv and Atom
Notes on defining PySide slots
[Python] Notes on data analysis
flask
Notes on optimization using Pytorch
Notes on installing Python on Mac
Notes on studying multidimensional scaling
flask
Notes on installing pipenv on Mac
Notes on installing Anaconda 3 on Windows
Notes on imshow () in OpenCV
Notes on installing Python on CentOS
Notes on Python and dictionary types
Notes on package management with conda
Preparing to run Flask on EC2
[Golang] Notes on frequently used functions
Notes on how to use featuretools
Notes on installing Python using PyEnv
Deploy Flask app on heroku (bitterly)
Deploy the Flask app on Heroku
Notes on using rstrip with python.
Notes on accessing dashDB from python
Deploy the Flask app on heroku
Notes on how to use doctest
Notes on using matplotlib on the server
Notes on how to write requirements.txt
Notes on installing Ubuntu 18.04 on the XPS 15 7590
(Beginner) Notes on using pyenv on Mac
(Note) Notes on building TensorFlow + Flask + Nginx environment with Docker Compose
Notes for using OpenCV on Windows10 Python 3.8.3.
First Flask
Notes on running M5Stick V with uPyLoader
SQLAlchemy notes
pyenv notes
Notes on nfc.ContactlessFrontend () for nfcpy in python
Notes for installing Sublime Text on Ubuntu
Flask memo
Notes on creating static files in Django
Notes on standard input / output of Go
Link WAS and FLASK applications on docker
[Python] Run Flask on Google App Engine
Notes on running Azure Machine Learning locally
Notes on doing Japanese OCR with Python
SQL notes
Pandas notes
Sphinx notes
django notes
I was addicted to Flask on dotCloud
Notes on building Python and pyenv on Mac
Notes on implementing APNs tests using Pytest