feat: more routs with url params

This commit is contained in:
Christoph J. Scherr 2025-02-07 14:44:04 +01:00
parent 7a5bebb9ff
commit 9c5353c67a
Signed by: PlexSheep
GPG Key ID: 9EB784BB202BB7BB
2 changed files with 28 additions and 2 deletions

View File

@ -1,7 +1,33 @@
from flask import Flask
from markupsafe import escape
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
return r"""
<p>Hello, World!</p>
<a href="/user/blabla">blabla</a>
<a href="/user/by_uuid/b36e8035-1337-1337-1337-eab4d505d739">blabla id</a>
"""
@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return f'User {escape(username)}'
@app.route('/user/by_uuid/<uuid:user_id>')
def show_user_id(user_id):
# show the user profile for that user
return f'Your mom has this id: {escape(user_id)}'
@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an integer
return f'Post {post_id}'
@app.route('/path/<path:subpath>')
def show_subpath(subpath):
# show the subpath after /path/
return f'Subpath {escape(subpath)}'

2
run.sh
View File

@ -1,2 +1,2 @@
#!/bin/bash
flask --app flaskex/app run
flask --app flaskex/app run --debug