Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1个模式:_Python_Django - Fatal编程技术网

Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1个模式:

Python 诺维森匹配'的正/反转;细节';带参数';(';';,)';没有找到。尝试了1个模式:,python,django,Python,Django,我正在一步一步地学习django教程,但无法找出出现此错误的原因: NoReverseMatch at /polls/ Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<pk>[0-9]+)/$'] 轮询/url.py app_name = 'polls' urlpatterns = [ path('', views.IndexView.as_vie

我正在一步一步地学习django教程,但无法找出出现此错误的原因:

NoReverseMatch at /polls/

Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['polls/(?P<pk>[0-9]+)/$']
轮询/url.py

app_name = 'polls'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'),
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote'),
]
app_name='polls'
URL模式=[
路径(“”,views.IndexView.as_view(),name='index'),
路径('/',views.DetailView.as_view(),name='detail'),
路径('/results/',views.ResultsView.as_view(),name='results'),
路径('/vote/',views.vote,name='vote'),
]
polls/index.html

<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>

  • 模板中的
    查询集
    作为
    最新问题列表
    传递,这是
    问题
    对象的集合,因此您应该迭代:

    <ul>
      {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
      {% endfor %}
    </ul>
      {最新问题列表%中的问题%
    • {%endfor%}
    上下文是
    最新的问题列表
    不是
    问题
    。您的详细信息查看功能!!!请
    <ul>
      {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
      {% endfor %}
    </ul>