Django html
时间: 2023-10-26 22:06:19 浏览: 50
Django is a web framework that uses the Model-View-Controller (MVC) architectural pattern. In Django, the View is responsible for rendering the HTML templates.
HTML (Hypertext Markup Language) is a markup language used to create web pages. It is used to define the structure of a web page and its content.
When building a web application with Django, you create HTML templates that define the structure and layout of your web pages. Django's template language allows you to insert dynamic content into your HTML templates, such as data from a database or user input.
Here's an example of a Django HTML template:
```
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Welcome to my website!</h1>
{% if user.is_authenticated %}
<p>Hello, {{ user.username }}!</p>
{% else %}
<p>Please log in to access the site.</p>
{% endif %}
<ul>
{% for post in posts %}
<li><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</body>
</html>
```
In this template, we have a basic HTML structure with a title and a heading. We use Django's template syntax to check if the user is authenticated and display a personalized message. We also use a for loop to display a list of posts.
Overall, Django's HTML templates provide a powerful way to create dynamic web pages with ease.