What is regex for / urlchecker / http: //www.google.com

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

I've tried doing:

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

      

But it didn't work. Does anyone know what I am doing wrong?

Also, is there generally a good resource for learning regex specifically for python / django?

Thanks guys!

+1


source to share


2 answers


Try this instead:

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



This is different from yours:

  • It will take something after "urlcheck /", not just "words".
  • This does not cause the URL to end with a slash.
+2


source


I just learned a thing or two while pulling out hidden Python thread functions. The Python compiler re has a debug mode ! (Who knew? Well, apparently someone did :-) Anyway, it's worth reading.



0


source







All Articles