2đ
Letâs explain how to read NoReverseMatch
errors.
There are 5 variables visualized in error message:
- pattern name: shown right after âReverse forâ, between two apostrophes.
- list of passed positional arguments: showed after âwith argumentsâ, also between 2 apostrophes, in form of a tuple. Remember! All patterns are presented here in one tuple, what is probably confusing for you.
- dict of passed keyword arguments: showed after âand keyword argumentsâ, also between 2 apostrophes, in form of a dict.
- number of tried patterns: showed after ânot found.â, as integer.
- list of tried patterns: showed after âpattern(s) tried:â, as python list.
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()