[Answered ]-Why this string comes with appending some special characters?

2👍

✅

Let’s explain how to read NoReverseMatch errors.

There are 5 variables visualized in error message:

  1. pattern name: shown right after “Reverse for”, between two apostrophes.
  2. 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.
  3. dict of passed keyword arguments: showed after “and keyword arguments”, also between 2 apostrophes, in form of a dict.
  4. number of tried patterns: showed after “not found.”, as integer.
  5. 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")),
]
  1. 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()

đŸ‘€GwynBleidD

Leave a comment