0

In the Django templating system, how does one include a template from within a subfolder of the templates folder?

I have the directory included in TEMPLATE_DIRS along with the proper "loaders", and as far as I can tell I am calling things correctly from within my templates, but the for still does not appear.

Thanks!

Contents of 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"),
)

Base Template

{% 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>

Template extending base, that calls template from subdirectory registration

{% extends "base.html" %}
{% load cms_tags %}

{% block reg_form %}
  {% include "registration/registration_form.html" %}
{% endblock %}

Template in subdirectory 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 %}
ryanjdillon
  • 17,658
  • 9
  • 85
  • 110
  • What does your "base.html" template look like? Including a template that extends it into another template that already extends it seems weird to me. – Peter DeGlopper Dec 15 '13 at 23:33
  • Yeah, the ``registration_form.html`` template was from somebody's git repository that I pulled. I tried modifying that to extend to ``template_1.html``, but that didn't seem to work either. – ryanjdillon Dec 15 '13 at 23:37
  • It might not have to extend anything if you just want it to render a bit of HTML. – Peter DeGlopper Dec 15 '13 at 23:40
  • I hope to be able to call templates located in subdirectories of my ``app/template/`` folder regardless of this example. There is an answer here (http://stackoverflow.com/a/15411829/943773) that relates to this, but I can't see what I am doing differently. Perhaps you could explain the difference of rendering only HTML versus other content? Thanks! – ryanjdillon Dec 16 '13 at 09:32
  • 1
    What I mean is that extend is usually used when you have an existing template that generates content that you want to reuse. It is not required. Unless your registration form is built from another template, you probably don't want to use it here. If you do use extend only content in blocks named in the parent will be rendered. I would test first rendering just a simple bit of text or html to pin down whether it isn't finding your template or whether it's rendering wrong. – Peter DeGlopper Dec 16 '13 at 17:54

0 Answers0