在Django模板系统中,如何在模板文件夹的子文件夹中包含模板?
我有TEMPLATE_DIRS
中包含的目录以及正确的“加载器”,据我所知,我在模板中正确调用了东西,但for仍然没有出现。
谢谢!
settings.py
TEMPLATE_DEBUG = DEBUG
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_PATH, "templates"),
os.path.join(PROJECT_PATH, "templates/registration"),
os.path.join(PROJECT_PATH, "templates/profile"),
)
基本模板
{% load cms_tags sekizai_tags %}
<html>
<head>
{% render_block "css" %}
</head>
<body>
{% cms_toolbar %}
{% placeholder base_content %}
{% block base_content %}{% endblock %}
{% render_block "js" %}
</body>
</html>
模板扩展基础,从子目录registration
调用模板
{% extends "base.html" %}
{% load cms_tags %}
{% block reg_form %}
{% include "registration/registration_form.html" %}
{% endblock %}
子目录registration
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Submit' %}" />
</form>
{% endblock %}