Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created October 23, 2012 22:34
Show Gist options
  • Save benhosmer/3942165 to your computer and use it in GitHub Desktop.
Save benhosmer/3942165 to your computer and use it in GitHub Desktop.
Python Flask notes
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return "Hello World!"
@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):
return render_template('index.html', name=name)
if __name__ == "__main__":
app.run(debug=True)
'''
Create an index.html in /templates:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/styles.css" />
</head>
<body>
<h1>Hello {{ name }}</h1>
</body>
</html>
'''
'''
Or use this:
<html>
<head>
<link rel="stylesheet" type="text/css" href={{ url_for('static', filename='styles.css') }} />
</head>
<body>
<h1>Hello {{ name }}</h1>
</body>
</html>
'''
'''
Add your stylesheet in /static
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment