Junior — Middle
How to implement displaying the same content or data on all pages of a web application?
sobes.tech AI
Answer from AI
To display the same content on all pages of a web application, templates with a common base structure are usually used. In Python frameworks, such as Django or Flask, a base template is created, which contains common HTML code (header, menu, footer). Other pages inherit this base template and add unique content.
Example in Flask using Jinja2:
# base.html
<html>
<head><title>My Application</title></head>
<body>
<header>Common Header</header>
{% block content %}{% endblock %}
<footer>Common Footer</footer>
</body>
</html>
# page.html
{% extends "base.html" %}
{% block content %}
<p>Unique page content</p>
{% endblock %}
Thus, common elements are defined once and displayed on all pages, while unique content is inserted into blocks.