1
votes

I'm writing a url rewrite in django that when a person goes to http://mysite.com/urlchecker/http://www.google.com it sends the url: http://ww.google.com to a view as a string variable.

I tried doing:

(r'^urlchecker/(?P<url>\w+)/$', 'mysite.main.views.urlchecker'),

But that didn't work. Anyone know what I'm doing wrong?

Also, generally is there a good resource to learn regular expressions specifically for python/django?

Thanks guys!

2

2 Answers

2
votes

Try this instead:

(r'^urlchecker/(?P<url>.+)$', 'mysite.main.views.urlchecker'),

This differs from yours in that:

  • It will take anything after 'urlcheck/', not just "word" characters.
  • It does not force the url to end in a slash.
0
votes

I just learned something while grazing the Hidden Features of Python thread. Python's re compiler has a debug mode! (Who knew? Well, apparently someone did :-) Anyway, it's worth a read.