feat: static files
This commit is contained in:
parent
9c5353c67a
commit
42143eea27
|
@ -1,33 +1,48 @@
|
||||||
from flask import Flask
|
from flask import Flask, url_for
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello_world():
|
def index():
|
||||||
return r"""
|
return f"""
|
||||||
|
<head>
|
||||||
|
<title>Deine Mama</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{url_for('static', filename='style.css')}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
<p>Hello, World!</p>
|
<p>Hello, World!</p>
|
||||||
<a href="/user/blabla">blabla</a>
|
<a href="/user/blabla">blabla</a>
|
||||||
<a href="/user/by_uuid/b36e8035-1337-1337-1337-eab4d505d739">blabla id</a>
|
<a href="/user/by_uuid/b36e8035-1337-1337-1337-eab4d505d739">blabla id</a>
|
||||||
|
</body>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@app.route('/user/<username>')
|
@app.route('/user/<username>')
|
||||||
def show_user_profile(username):
|
def user_profile(username):
|
||||||
# show the user profile for that user
|
# show the user profile for that user
|
||||||
return f'User {escape(username)}'
|
return f'User {escape(username)}'
|
||||||
|
|
||||||
@app.route('/user/by_uuid/<uuid:user_id>')
|
@app.route('/user/by_uuid/<uuid:user_id>')
|
||||||
def show_user_id(user_id):
|
def user_id(user_id):
|
||||||
# show the user profile for that user
|
# show the user profile for that user
|
||||||
return f'Your mom has this id: {escape(user_id)}'
|
return f'Your mom has this id: {escape(user_id)}'
|
||||||
|
|
||||||
@app.route('/post/<int:post_id>')
|
@app.route('/post/<int:post_id>')
|
||||||
def show_post(post_id):
|
def post_show(post_id):
|
||||||
# show the post with the given id, the id is an integer
|
# show the post with the given id, the id is an integer
|
||||||
return f'Post {post_id}'
|
return f'Post {post_id}'
|
||||||
|
|
||||||
@app.route('/path/<path:subpath>')
|
@app.route('/path/<path:subpath>')
|
||||||
def show_subpath(subpath):
|
def subpath_show(subpath):
|
||||||
# show the subpath after /path/
|
# show the subpath after /path/
|
||||||
return f'Subpath {escape(subpath)}'
|
return f'Subpath {escape(subpath)}'
|
||||||
|
|
||||||
|
with app.test_request_context():
|
||||||
|
print("{:=^80}".format("URIs"))
|
||||||
|
print(url_for('index'))
|
||||||
|
print(url_for('user_profile', username="yo mama"))
|
||||||
|
print(url_for('user_id' ,user_id="blabla"))
|
||||||
|
print(url_for('post_show', post_id=1337))
|
||||||
|
print(url_for('subpath_show', subpath="blablabla"))
|
||||||
|
print(url_for('static', filename='style.css'))
|
||||||
|
print("=" * 80)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class Bla:
|
||||||
|
def foo(self):
|
||||||
|
self.do()
|
||||||
|
self.the()
|
||||||
|
self.thing()
|
|
@ -0,0 +1,3 @@
|
||||||
|
body {
|
||||||
|
background: tomato;
|
||||||
|
}
|
Loading…
Reference in New Issue