Last active
July 11, 2019 03:49
-
-
Save purarue/1ce1ee76e04b9952beba2d4d63f4fdf7 to your computer and use it in GitHub Desktop.
basic one file Flask example to explain routes and replacement fields
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 | |
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