python - 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>
模板嵌套在投票应用程序的模板文件夹中的投票文件夹中。我不明白为什么我会收到详细信息错误。我怎样才能解决这个问题?
解决方案
它是您代码中的错字。您需要在视图中更改template_name="polls/details.html"
为template_name="polls/detail.html"
。
或者,只需将polls/detail.html
文件重命名为polls/details.html
.
推荐阅读
- java - JMeter - 执行 QUIC 请求
- c - 我们可以同时入队和出队吗
- php - 在单个提交按钮事件上一次进行 8 个以上的 ajax 调用是一种好习惯吗?
- ios - Swift - 自定义单元格内容(UILabel、UIImageView)
- python - 如何在列表中找到最常见的起始字母?
- python - 如何在嵌套列表的每个子列表中指定特定元素的索引?
- javascript - 重新加载页面后如何隐藏模式并显示另一个模式?
- javascript - How to type async function using typescript
- ffmpeg - ffmpeg缩放nvenc保持纵横比
- android - 为什么 R8 不重命名所有方法和类?