Skip to content

Commit

Permalink
Merge pull request #1 from hexlet-components/templates-inheritance
Browse files Browse the repository at this point in the history
Templates inheritance
  • Loading branch information
sgmdlt authored Aug 14, 2024
2 parents 2db2292 + 1a2cf62 commit fed93f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def courses(id):


@app.route('/users/<id>')
def users(id):
def show_user(id):
user = {
"id": id,
"name": f"user-{id}"
Expand Down
18 changes: 18 additions & 0 deletions templates/courses/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "layout.html" %}

{% block title %}Курсы{% endblock %}

{% block content %}
<table>
{% for course in courses %}
<tr>
<td>
{{ course.id }}
</td>
<td>
{{ course.name }}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
19 changes: 19 additions & 0 deletions templates/courses/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}Flask проект{% endblock %}</title>
</head>
<body>
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/">Главная</a></li>
<li><a href="/courses/">Курсы</a></li>
</ul>
{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
6 changes: 2 additions & 4 deletions templates/users/show.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<h1>
id = {{ user.id }}
nickname = {{ user.name }}
</h1>
<div>id = {{ user.id }}</div>
<div>nickname = {{ user.name }}</div>

0 comments on commit fed93f7

Please sign in to comment.