Answer the question
In order to leave comments, you need to log in
Why are blocks not included in Django?
Help solve the problem. Templates in django don't work.
Project structure:
---project
|--project
| |--settings.py
| |--urls.py
|--app1
| |--static
| | |--css
| | | |--style.css
| |--templates
| | |--left.html
| | |--right.html
| |--urls.py
| |--models.py
| |--views.py
|--temlpates
| |--index.html
|--manage.py
...
INSTALLED_APPS = [
...
'app1',
...
...
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'templates',
'app1/templates'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
...
STATIC_URL = '/static/'
from django.shortcuts import render_to_response
def index(request):
return render_to_response('index.html')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="main">
{% block left %}{% endblock %}
{% block right %}{% endblock %}
</div>
</body>
</html>
{% extends 'index.html' %}
{% block left %}
<p>Абра-кадабра!</p>
{% endblock %}
{% extends 'index.html' %}
{% block right %}
<p>Сим-селявим!</p>
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="main">
</div>
</body>
</html>
static
are loaded. I tried to transfer left.html and right.html to the folder project/temlpates
and to project/app1/templates
- to no avail. What am I doing wrong? I can not understand? Perhaps I misinterpreted the template manual? Answer the question
In order to leave comments, you need to log in
def left(request):
return render_to_response('left.html')
{% extends 'index.html' %}
{% block left %}
<p>Абра-кадабра!</p>
{% endblock %}
{% block right %}
<p>Сим-селявим!</p>
{% endblock %}
If you want to see the blocks - set them in the index file inside the blocks.
Templates work a little differently. In the case of extend, they move if they are referenced by the django url, then the template looks for the parent in the specified extend and inserts the blocks.
You can try include, but the django template engine is bent in performance if there are a lot of includes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question