Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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
NoReverseMatch:与#x27相反;细节';没有找到。(Django教程)_Django_Python 3.x_Django 2.0 - Fatal编程技术网

NoReverseMatch:与#x27相反;细节';没有找到。(Django教程)

NoReverseMatch:与#x27相反;细节';没有找到。(Django教程),django,python-3.x,django-2.0,Django,Python 3.x,Django 2.0,我一直在学习Django 2教程 我得到了以下错误: #Error: #django.urls.exceptions.NoReverseMatch #django.urls.exceptions.NoReverseMatch: Reverse for 'detail' not found. 'detail' is not a valid view function or pattern #name. 在谷歌上搜索了一下,确认我已将我的视图命名为“详细信息”,并将我的应用程序命名为 下面是我的代

我一直在学习Django 2教程

我得到了以下错误:

#Error:
#django.urls.exceptions.NoReverseMatch
#django.urls.exceptions.NoReverseMatch: Reverse for 'detail' not found. 'detail' is not a valid view function or pattern #name.
在谷歌上搜索了一下,确认我已将我的视图命名为“详细信息”,并将我的应用程序命名为

下面是我的代码。 请告诉我怎么了。我在背诵教程,但这一点出现了。我如何修复它与教程保持一致?谢谢大家!

档案: mysite/polls/templates/polls/index.html

{% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
    {% endfor %}
其他: mysite/url.py

urlpatterns = [
    path('polls/', include('polls.urls', namespace='polls')),
    path('admin/', admin.site.urls),
]

您尚未在views.py文件中定义任何名为“detail”的函数

添加此代码

def detail(request, id):
    context = dict()
    return render(request, 'polls/index.html', context)
您还必须添加结果和投票函数


从index.html文件中删除注释行。这些行中的语法不正确,Django在呈现之前也会尝试解析注释行。

mysite/url.py
中删除
命名空间
,因为您已经指定了应用程序的
app\u名称


或者您可以删除
app_名称
,保留
名称空间
(不确定这在Django 2.0中是否有效)。

视图的位置。详细信息?def detail(request,question_id):question=get_object_或_404(question,pk=question_id)返回render(request,'polls/detail.html',{'question':question})我的整个polls/views.py文件:请建议@gahanMy settings.py文件:我确实添加了详细信息功能。这是我完整的views.py文件:django.urls.exceptions.NoReverseMatch django.urls.exceptions.NoReverseMatch:未找到“详细信息”的反向“详细信息”不是有效的视图函数或模式名称。
urlpatterns = [
    path('polls/', include('polls.urls', namespace='polls')),
    path('admin/', admin.site.urls),
]
def detail(request, id):
    context = dict()
    return render(request, 'polls/index.html', context)