Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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 有趣的Django`NoReverseMatch错误`_Python_Html_Django - Fatal编程技术网

Python 有趣的Django`NoReverseMatch错误`

Python 有趣的Django`NoReverseMatch错误`,python,html,django,Python,Html,Django,在我决定对模板的某些部分使用djangoextends以使其可重用之前,一切都正常工作,现在我得到了 NoReverseMatch错误 url.py: url(r'^school/(?P<id>\d+)/(?P<name>[-\w]+)/$', views.school_profile, name='school'), def school_profile(request, id, name): #Some actions here... <p clas

在我决定对模板的某些部分使用django
extends
以使其可重用之前,一切都正常工作,现在我得到了
NoReverseMatch错误

url.py

url(r'^school/(?P<id>\d+)/(?P<name>[-\w]+)/$', views.school_profile, name='school'),
def school_profile(request, id, name):
    #Some actions here...
<p class='mini_links'><a href="{% url 'mysite:school' user.school.id user.school|slugify %}">{{user.school|title}} </a></p>
{% extends 'mysite/base.html' %}

{% block mainBody %} 
    {% include 'mysite/extract.html' %}
{% endblock %}
index.html

url(r'^school/(?P<id>\d+)/(?P<name>[-\w]+)/$', views.school_profile, name='school'),
def school_profile(request, id, name):
    #Some actions here...
<p class='mini_links'><a href="{% url 'mysite:school' user.school.id user.school|slugify %}">{{user.school|title}} </a></p>
{% extends 'mysite/base.html' %}

{% block mainBody %} 
    {% include 'mysite/extract.html' %}
{% endblock %}
我真的不知道我做得不对

错误堆栈: NoReverseMatch at/mysite/

Reverse for 'school' with arguments '('', u'')' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Request Method:     GET
Request URL:    http://127.0.0.1:8000/mysite/
Django Version:     1.6
Exception Type:     NoReverseMatch
Exception Value:    

Reverse for 'school_profile' with arguments '('', u'')' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Exception Location:     C:\Python27\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 429
Python Executable:  C:\Python27\python.exe
Python Version:     2.7.9
Python Path:    

['C:\\Python27\\Lib\\site-packages\\HubEnv\\Scripts\\myApp',
 'C:\\Python27\\lib\\site-packages\\mysql_python-1.2.5-py2.7-win32.egg',
 'C:\\windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']

Server time:    Sun, 29 Mar 2015 21:50:52 +0100

您正在尝试反转名称空间的URL,但似乎尚未定义URL。只需从背面删除
mysite:
名称空间:

{% url 'school' user.school.id user.school|slugify %}

更新:您的代码和堆栈跟踪没有相互确认。看起来您没有粘贴正在运行的实际代码。因此,要么将您的反向更改为
{%url'mysite:school'%}
,要么将您的url名称更改为
..,name='school\u profile')

我尝试了此操作,但得到了一个意外的关键字参数“namespace”。抱歉,我的错误。您没有包含另一个
url.py
,因此不能在此处使用
命名空间。查看我的更新答案我也尝试了编辑过的答案,但仍然收到
NoReverseMatch error
。这是您的主
url.py
还是应用程序目录中的那一个?如果是这样的话,请也发布主目录。它位于我的应用程序目录
(url(r'^mysite/',include('mysite.urls',namespace='mysite'),)