模板不存在 - Django

时间:2015-12-20 14:09:18

标签: python django templates path

我正在尝试通过扩展index.html来创建base.html。问题是,Django表示没有这样的模板。它找不到它。我已经尝试了更多的路径,但没有一条路可行。

这是我的项目结构: enter image description here

上传/模板/上传/ index.html中:

{% extends 'base.html' %}
{% block content %}
    <form action="/process_text/" method="post" enctype="multipart/form-data">{% csrf_token %}
        {{ lang_drop_down_form }}
        <br>
        {{ text_area_form }}
        {{ file_upload_form }}
        <input align="center" type="submit" value="upload">
    </form>

    {% if user.is_authenticated %}
    <p>Hello {{ user.name }}</p>
    {% endif %}
{% endblock %}

上传/模板/上传/ base.html:(jumbotron bootstrap模板)

.
..
...
    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      <div class="container">
        {% block content %}
        {% endblock %}
      </div>
    </div>
...
..
.

例外:

TemplateDoesNotExist at /
mysite/uploading/templates/uploading/base.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.7
Exception Type: TemplateDoesNotExist
Exception Value:    
mysite/uploading/templates/uploading/base.html
Exception Location: C:\Python27\lib\site-packages\django\template\engine.py in find_template, line 146
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.10
Python Path:    
['C:\\Users\\Milano\\PycharmProjects\\mysite',
 'C:\\Windows\\SYSTEM32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\win32',
 'C:\\Python27\\lib\\site-packages\\win32\\lib',
 'C:\\Python27\\lib\\site-packages\\Pythonwin']
Server time:    Sun, 20 Dec 2015 15:08:11 +0100

你知道该怎么办吗?

1 个答案:

答案 0 :(得分:2)

您需要将您的扩展标记更改为:

{% extends 'uploading/base.html' %}

模板位于uploading/templates/uploading/base.html。应用模板目录为uploading/templates,因此在Django中引用它时需要使用余数uploading/base.html