Created
October 18, 2016 22:27
-
-
Save rpasta42/4e1bf53d1ff03360ebb6faee41e6dc42 to your computer and use it in GitHub Desktop.
Flask example
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
===================backend code serv.py | |
from flask import render_template | |
#we open database file which lets us store stuff in it | |
database = OpenDatabase("C:/location/of/database/filename.db") | |
@app.route('/hello/') | |
@app.route('/hello/<name>') | |
def hello(name=None): | |
if name is not None: | |
name = name + " this string is added to every name" | |
database.store(name) #add name to database | |
return render_template('hello.html', name=name) | |
===================hello.html | |
backend code generates html from this template | |
<html> | |
<title>Hello from Flask</title> | |
{% if name %} | |
<h1>Hello {{ name }}!</h1> | |
{% else %} | |
<h1>Hello, World!</h1> | |
{% endif %} | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment