Django URL 语法错误
我正在创建一个维基应用程序。当我在 urls.py 中为我的应用程序创建 url 时,我收到语法错误消息。我不擅长正则表达式。
这是我的代码,
(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'),
我的错误是,
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
正则表达式有什么问题吗?我确实阅读了 django 文档,但仍然不知道。
谢谢!
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/
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!
, 'wikicamp.wiki.views.edit_page'),
(r'wikicamp/(?<page_name>[^/]+)/save/
And my error is,
Is there anything wrong in the regular expression? I did read django documentation but still have no idea.
Thanks!
, 'wikicamp.wiki.views.save_page'),
(r'wikicamp/(?<page_name>[^/]+)/
And my error is,
Is there anything wrong in the regular expression? I did read django documentation but still have no idea.
Thanks!
, 'wikicamp.wiki.views.view_page'),
And my error is,
Is there anything wrong in the regular expression? I did read django documentation but still have no idea.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您命名的捕获组缺少“P”。这样做:
Your named capture groups are missing the 'P'. Do it like so:
根据 http://docs.python.org/library/re.html 语法对于命名组来说
这意味着你应该有
According to http://docs.python.org/library/re.html the syntax for named groups is
That means you should have