0% found this document useful (0 votes)
80 views1 page

Flask Cheat Sheet: Create App Routing Templates

Flask is a popular Python web development framework. The cheat sheet outlines key concepts for Flask including creating an app, routing, templates, JSON responses, handling requests, and redirects. It provides examples of common tasks like creating routes, rendering templates, accessing request data, and returning JSON responses in 3 sentences or less.

Uploaded by

hamsir anci
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views1 page

Flask Cheat Sheet: Create App Routing Templates

Flask is a popular Python web development framework. The cheat sheet outlines key concepts for Flask including creating an app, routing, templates, JSON responses, handling requests, and redirects. It provides examples of common tasks like creating routes, rendering templates, accessing request data, and returning JSON responses in 3 sentences or less.

Uploaded by

hamsir anci
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

FLASK CHEAT SHEET

FLASK
#1 PYTHON
WEB DEV
FRAMEWORK DOCS:
FLASK.PALLETSPROJECTS.COM/

CREATE APP ROUTING TEMPLATES

from flask import Flask @app.route( from flask import


'/hello/<string: name>' render_template
app = Flask(__name__) )
def hello(name): @app.route('/')
@app.route('/hello') return 'Hello ' + name def index():
def hello(): return render_template(
return 'Hello, World!' 'template_file.html',
var1=value1
if __name__ == '__main__': )
app.run(debug=True)

JSON REQUEST REDIRECT


RESPONSE DATA

mport jsonify request.args['name'] rom flask import


#query string arguments url_for, redirect
@app.route('/returnJSON')
def jsonAPI(): request.form['name'] @app.route('/home')
num_dict = { #form data def home():
'numbers' : [1, 2, 3] return
} request.method render_template('home.html')
return jsonify( #request type
{'output' : num_dict} @app.route('/redirect')
) def redirect_example():
return
redirect(url_for('home'))

100 DAYS OF CODE WITH PYTHON

You might also like