0

I am creating a wiki app. And when I create url for my app in urls.py I get syntax error message. I am not good at regular expressions.

Here is my code,

(r'wikicamp/(?<page_name>[^/]+)/edit/$', 'wikicamp.wiki.views.edit_page'),
(r'wikicamp/(?<page_name>[^/]+)/save/$', 'wikicamp.wiki.views.save_page'),
(r'wikicamp/(?<page_name>[^/]+)/$', 'wikicamp.wiki.views.view_page'),

And my error is,

error at /
syntax error
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.2.5
Exception Type: error
Exception Value:    
syntax error
Exception Location: /usr/lib/python2.6/re.py in _compile, line 245
Python Executable:  /usr/bin/python
Python Version: 2.6.6
Python Path:    ['/home/ztron/wikicamp', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0']
Server time:    Wed, 13 Apr 2011 15:21:18 -0500

Is there anything wrong in the regular expression? I did read django documentation but still have no idea.

Thanks!

2 Answers 2

4

Your named capture groups are missing the 'P'. Do it like so:

(r'wikicamp/(?P<page_name>[^/]+)/edit/$', 'wikicamp.wiki.views.edit_page'),
(r'wikicamp/(?P<page_name>[^/]+)/save/$', 'wikicamp.wiki.views.save_page'),
(r'wikicamp/(?P<page_name>[^/]+)/$', 'wikicamp.wiki.views.view_page'),
Sign up to request clarification or add additional context in comments.

2 Comments

The P is a python specific bit of syntax that indicates that this is "python named group", as I recall.
@Soviut: You can use this syntax with PHP as well (and any other tool which uses the excellent PCRE library).
0

According to http://docs.python.org/library/re.html the syntax for named groups is

(?P<name>...)

That means you should have

(r'wikicamp/(?P<page_name>[^/]+)/edit/$', 'wikicamp.wiki.views.edit_page'),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.