1

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!

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
rksprst
  • 6,471
  • 18
  • 54
  • 81

2 Answers2

2

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.
Peter Rowell
  • 17,605
  • 2
  • 49
  • 65
0

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.

Community
  • 1
  • 1
Peter Rowell
  • 17,605
  • 2
  • 49
  • 65