Reputation: 127
Here is my html code
<b><a href="{% url 'polls:logout_info' %}">logout</a></b>
<b><a href={% url 'polls:edit' author %}>Edit</a></b>
<br>
<center><h2> -- WELCOME {{ name }} -- </h2></center>
{% if errors %}
<ul>
{% for error in errors %}
<center>{{ error }}</center>
{% endfor %}
</ul>
{% endif %}<br>
Here is url.py code (just showing url related to this code)
from django.conf.urls import url
from . import views
urlpatterns = [
url( r'^login/$', views.login ,name='login'),
url( r'^saveinfo/$', views.saveinfo ,name='saveinfo'),
url( r'^indexmain/$', views.indexmain ,name='indexmain'),
url( r'^indexmain1/$', views.indexmain1 ,name='indexmain1'),
url( r'^homemain/$', views.homemain ,name='homemain'),
url( r'^logout_info/$', views.logout_info ,name='logout_info'),
url( r'^edit/(?P<author>[a-z]+)/$', views.edit ,name='edit'),
]
I got this error:
NoReverseMatch at /polls/login/ Reverse for '' with arguments '('pratiksha ',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Why this string comes with appending some special characters??
Upvotes: 1
Views: 302
Reputation: 20569
Let's explain how to read NoReverseMatch
errors.
There are 5 variables visualized in error message:
Now, some understanding how URL reversing works: django will try to find all urlpatterns that match pattern name with one that you've provided. For each pattern name it will check if provided positional or keyword arguments can be inserted into parameters in place of regular expression groups. All of this patterns will be listed as tried patterns.
Now, from error message we can find out that
1. no patterns were tried, so there was no patterns found matching provided pattern name. Solution for that problem is easy: you're passing 'polls:edit' into url
tag, but your pattern is named 'edit' and it is not registered in namespace 'polls'. You can fix that by passing just 'edit' or by moving your pattern into namespace:
urlpatterns = [
url( r'^login/$', views.login ,name='login'),
url( r'^saveinfo/$', views.saveinfo ,name='saveinfo'),
url( r'^indexmain/$', views.indexmain ,name='indexmain'),
url( r'^indexmain1/$', views.indexmain1 ,name='indexmain1'),
url( r'^homemain/$', views.homemain ,name='homemain'),
url( r'^', include([
url( r'^logout_info/$', views.logout_info ,name='logout_info'),
url( r'^edit/(?P<author>[a-z]+)/$', views.edit ,name='edit'),
], namespace="polls")),
]
there is an extra whitespace at the end of 1st (and only) positional parameter. That won't be accepted by your regex, so it won't be matched. You must get rid of that whitespace. In your view simply call:
context['author'] = context['author'].strip()
Upvotes: 2