Created
October 23, 2012 22:34
-
-
Save benhosmer/3942165 to your computer and use it in GitHub Desktop.
Python Flask notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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