Django sometimes throws NoReverseMatch

I get a random error in rendering a django template; I sometimes get NoReverseMatch at the following URL:

    url(r'^student-agreement/(?P<code>[\w:-]+)$',
        StudentAgreementView.as_view(),
        name='student-agreement'),

The argument codeis created by calling the signing.dumps()identifier of the object that creates the string, such as 'MjExMg:1Z0H6s:1H19SjhO2CCAlAUgkiYLvyYLSzI'- as far as I can tell, this should match the provided regular expression. However, after trying the test, for example:

for i in range(20)
    print reverse('student-agreement', kwargs={'code':signing.dumps(i)})

will quickly output NoReverseMatch.

Here is a Traceback example:

Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/sis_esv_repo/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-58-f02835044aa6>", line 2, in <module>
    print reverse('student-agreement', kwargs={'code':signing.dumps(i)})
  File "/home/vagrant/.virtualenvs/sis_esv_repo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 551, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "/home/vagrant/.virtualenvs/sis_esv_repo/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 468, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'student-agreement' with arguments '()' and keyword arguments '{'code': 'Mg:1Z0H9L:ltHc7mAAteN7jBHRBIuT-Zbzt18'}' not found. 1 pattern(s) tried: ['school/student-agreement/(?P<code>[\\w:-_]+)$']
+4
source share
2 answers

, , , , , - , : (?P<code>[\w:-_]+), (?P<code>[\w:-]+) - :-_ : _, . , , . \w , , (?P<code>[\w:_-]+) .

@fasouto !

0

_.

-1

All Articles