首页 > 解决方案 > TemplateDoesNotExist at /poll/1/ -Django 教程

问题描述

我收到一个错误,TemplateDoesNotExist at /polls/1/ 我应该在我投票后看到投票结果。错误是:

polls/details.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/polls/1/
Django Version: 3.0.8
Exception Type: TemplateDoesNotExist
Exception Value:    
polls/details.html
Exception Location: C:\Users\JohnDoe\Documents\JaneDoe\Django\trydjango\tutorial\lib\site-packages\django\template\loader.py in get_template, line 19
Python Executable:  C:\Users\JohnDoe\Documents\JaneDoe\Django\trydjango\tutorial\Scripts\python.exe
Python Version: 3.8.4

详细信息.html

<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
    <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
    <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
{% endfor %}
<input type="submit" value="Vote">
</form>

模板嵌套在投票应用程序的模板文件夹中的投票文件夹中。我不明白为什么我会收到详细信息错误。我怎样才能解决这个问题?

标签: pythondjango

解决方案


它是您代码中的错字。您需要在视图中更改template_name="polls/details.html"template_name="polls/detail.html"

或者,只需将polls/detail.html文件重命名为polls/details.html.


推荐阅读