feat: more routs with url params
This commit is contained in:
parent
7a5bebb9ff
commit
9c5353c67a
|
@ -1,7 +1,33 @@
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from markupsafe import escape
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello_world():
|
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)}'
|
||||||
|
|
Loading…
Reference in New Issue