Reputation: 2189
Everything was working until I decided to use django extends
for some part of my template to make them reuseable and now I am getting
NoReverseMatch error
.
url.py:
url(r'^school/(?P<id>\d+)/(?P<name>[-\w]+)/$', views.school_profile, name='school'),
views.py:
def school_profile(request, id, name):
#Some actions here...
index.html:
<p class='mini_links'><a href="{% url 'mysite:school' user.school.id user.school|slugify %}">{{user.school|title}} </a></p>
That is the html line that is generating the error and I can't for the life of me figure it out.
NOTE:
Formally the html link is just in index.html
but I have now extracted (extract.html) away and it is now coming through:
index.html:
{% extends 'mysite/base.html' %}
{% block mainBody %}
{% include 'mysite/extract.html' %}
{% endblock %}
I really can't figure out what I am not doing right.
Error Stack: 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
Upvotes: 1
Views: 296
Reputation: 59238
You are trying to reverse a namespaced URL but you don't seem to have defined one. Just remove the mysite:
namespace from your reverse:
{% url 'school' user.school.id user.school|slugify %}
Update: Your code and stack trace are not confirming each other. It looks like you did not paste the actual code you are running. So either change your reverse to {% url 'mysite:school' %}
or your url name to ..., name='school_profile')
Upvotes: 1