From Fedora Project Wiki
(Created page with "wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py") |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py | = Setup = | ||
Create directory to hold virtualenv | |||
mkdir python_web | |||
cd python_web | |||
Create virtualenv & install flask | |||
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py | |||
python virtualenv.py flask | |||
source flask/bin/activate | |||
pip install flask flask-sqlalchemy flask-wtf | |||
= Hello World = | |||
Create directory/file structure | |||
mkdir hello_world | |||
cd hello_world | |||
== Dummy App == | |||
''app_01.py'' | |||
<pre> | |||
from flask import Flask | |||
DEBUG = True | |||
HOST = '0.0.0.0' | |||
app = Flask(__name__) | |||
app.config.from_object(__name__) | |||
@app.route('/') | |||
@app.route('/index') | |||
def index(): | |||
return "Hello, World!" | |||
if __name__ == '__main__': | |||
app.run(host = app.config['HOST'], debug = app.config['DEBUG']) | |||
</pre> | |||
== HTML == | |||
''app_02.py'' | |||
<pre> | |||
from flask import Flask | |||
HOST = '0.0.0.0' | |||
DEBUG = True | |||
app = Flask(__name__) | |||
app.config.from_object(__name__) | |||
@app.route('/') | |||
@app.route('/index') | |||
def index(): | |||
args = {'user': 'John Doe'} | |||
page = """ | |||
<html> | |||
<head> | |||
<title>Home Page</title> | |||
</head> | |||
<body> | |||
<h1>Hello, %(user)s</h1> | |||
</body> | |||
</html> | |||
""" | |||
return page % args | |||
if __name__ == '__main__': | |||
app.run(host = app.config['HOST'], debug = app.config['DEBUG']) | |||
</pre> | |||
== Templates == | |||
http://jinja.pocoo.org/docs/templates/ | |||
Create a directory to store templates | |||
mkdir templates |
Latest revision as of 18:14, 5 December 2012
Setup
Create directory to hold virtualenv
mkdir python_web cd python_web
Create virtualenv & install flask
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py python virtualenv.py flask source flask/bin/activate pip install flask flask-sqlalchemy flask-wtf
Hello World
Create directory/file structure
mkdir hello_world cd hello_world
Dummy App
app_01.py
from flask import Flask DEBUG = True HOST = '0.0.0.0' app = Flask(__name__) app.config.from_object(__name__) @app.route('/') @app.route('/index') def index(): return "Hello, World!" if __name__ == '__main__': app.run(host = app.config['HOST'], debug = app.config['DEBUG'])
HTML
app_02.py
from flask import Flask HOST = '0.0.0.0' DEBUG = True app = Flask(__name__) app.config.from_object(__name__) @app.route('/') @app.route('/index') def index(): args = {'user': 'John Doe'} page = """ <html> <head> <title>Home Page</title> </head> <body> <h1>Hello, %(user)s</h1> </body> </html> """ return page % args if __name__ == '__main__': app.run(host = app.config['HOST'], debug = app.config['DEBUG'])
Templates
http://jinja.pocoo.org/docs/templates/
Create a directory to store templates
mkdir templates