【发布时间】:2020-07-13 23:43:16
【问题描述】:
Django 版本: 3.0.8
Python 版本: 3.8.0
我正在做一个 Django 教程,我在下面遇到了这个错误
下面的“detail.html”
{% extends 'polls/base.html' %}
{% block main_content %}
<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>
{% endblock %}
下面的“base.html”
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Base</title>
</head>
<body>
<hr>
<p> Header </p>
<hr>
{% block main_content %}
{% endblock %}
{% include "polls/footer.html" %}
</body>
</html>
如果有人能提供帮助,我将不胜感激。
【问题讨论】:
-
请同时添加
footer.html的代码 -
向我们展示你的 urls.py
-
'from django.conf.urls import * from .导入视图 urlpatterns = \ [ url(r'^$', views.index, name="index"), url(r'^(?P
[0-9]+)/$', views.detail , name="detail"), url(r'^(?P [0-9]+)/results$', views.results, name="results"), url(r'^(?P [0-9]+)/votes$', views.votes, name="votes"), ] app_name = 'polls' ' -
页脚
-
这是一个错字,你的路线反向名称=投票不投票,你应该相应地编辑你的模板
标签: python-3.x django