rksprst
rksprst

Reputation: 6631

What is the regular expression for /urlchecker/http://www.google.com

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!

Upvotes: 2

Views: 301

Answers (2)

Peter Rowell
Peter Rowell

Reputation: 17713

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.

Upvotes: 0

Peter Rowell
Peter Rowell

Reputation: 17713

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.

Upvotes: 2

Related Questions