Flask: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 33: | Line 33: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
And the template | And the template | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="html"> | ||
<html> | <html> | ||
<head> | <head> |
Revision as of 04:26, 23 May 2021
Introduction
Quick tour of the python framework flask
Getting Started
from app import app
@app.route('/')
@app.route('/index')
def index():
user = {'username': 'Miguel'}
return '''
<html>
<head>
<title>Home Page - Microblog</title>
</head>
<body>
<h1>Hello, ''' + user['username'] + '''!</h1>
</body>
</html>'''
Routing
Templates
So flask like others such pug or egs has templates. Very similar indeed
from flask import render_template
from app import app
@app.route('/')
@app.route('/index')
def index():
user = {'username': 'Miguel'}
return render_template('index.html', title='Home', user=user)
And the template
<html>
<head>
<title>{{ title }} - Microblog</title>
</head>
<body>
<h1>Hello, {{ user.username }}!</h1>
</body>
</html>