шаблоны

This commit is contained in:
Toy Rik 2025-08-30 15:55:33 +03:00
parent a5f65ee9a8
commit 9b4e56a94e
5 changed files with 38 additions and 1 deletions

1
.flaskenv.example Normal file
View File

@ -0,0 +1 @@
FLASK_APP=microblog.py

1
.gitignore vendored
View File

@ -55,3 +55,4 @@ instance/
# Flask specific # Flask specific
webassets/ webassets/
/.flask.env

View File

@ -1,5 +1,18 @@
from flask import render_template
from app import app from app import app
@app.route('/') @app.route('/')
@app.route('/index') @app.route('/index')
def index(): def index():
return "Hello, word!" user = {'username': 'Miguel'}
posts = [
{
'author': {'username': 'John'},
'body': 'Beautiful day in Portland!'
},
{
'author': {'username': 'Susan'},
'body': 'The Avengers movie was so cool!'
}
]
return render_template('index.html', title='Home', user=user, posts=posts)

15
app/templates/base.html Normal file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
{% if title %}
<title>{{ title }} - Microblog</title>
{% else %}
<title>Welcome to Microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>

7
app/templates/index.html Normal file
View File

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block content %}
<h1>Hi, {{ user.username }}!</h1>
{% for post in posts %}
<div><p>{{ post.author.username }} says: <b>{{ post.body }}</b></p></div>
{% endfor %}
{% endblock %}