0

I want to match a url that has a token in it e.g http://example.com/success/dm00cmw1KnltYkAyJmRfKGdjJGc4\n. But I get error when I try to reverse match it using the following url pattern

url(r'success/(?P<token>.*)/$', 'payments_system.views.success_result_view', name='success')

I get the following error:

Reverse for 'success' with arguments '()' and keyword arguments '{'token': 'dm00cmw1KnltYkAyJmRfKGdjJGc4\n'}' not found. 1 pattern(s) tried: ['success/(?P<token>.*)/$']

I also tried \w+ or .+ but I get the same error. How can I much every character on a url?

Apostolos
  • 7,763
  • 17
  • 80
  • 150

1 Answers1

0

\n in python is a newline character. You need to escape the backslash, i.e. \\n, to treat it as a literal backslash, since newlines are not valid in an url, and .* doesn't match it.

Better would be to disallow such characters, and limit the token to e.g. [A-Za-z0-9].

knbk
  • 52,111
  • 9
  • 124
  • 122