Skip to content

Instantly share code, notes, and snippets.

@seanbreckenridge
Last active July 11, 2019 03:49
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 seanbreckenridge/1ce1ee76e04b9952beba2d4d63f4fdf7 to your computer and use it in GitHub Desktop.
Save seanbreckenridge/1ce1ee76e04b9952beba2d4d63f4fdf7 to your computer and use it in GitHub Desktop.
basic one file Flask example to explain routes and replacement fields
from flask import Flask
app = Flask(__name__)
@app.route("/")
def main():
return "Hello world"
def generate_style(class_name, color):
style = f"<style> .{class_name} {{ background-color: {color} }}</style>"
return style
@app.route("/user/<id>")
def user(id):
style_tag = generate_style("red", "red")
whole_page = """<html><head>{}</head><body><div class="red">Hello user number {}</div></body></html>""".format(style_tag, id)
return whole_page
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment