Skip to content

Instantly share code, notes, and snippets.

@rpasta42
Created October 18, 2016 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpasta42/4e1bf53d1ff03360ebb6faee41e6dc42 to your computer and use it in GitHub Desktop.
Save rpasta42/4e1bf53d1ff03360ebb6faee41e6dc42 to your computer and use it in GitHub Desktop.
Flask example
===================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