Django URL 语法错误

发布于 2024-11-01 07:18:40 字数 1251 浏览 2 评论 0原文

我正在创建一个维基应用程序。当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诠释孤独 2024-11-08 07:18:40

您命名的捕获组缺少“P”。这样做:

(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'),

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'),
醉生梦死 2024-11-08 07:18:40

根据 http://docs.python.org/library/re.html 语法对于命名组来说

(?P<name>...)

这意味着你应该有

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

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'),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文