【问题标题】:Django dynamic url. what am i doing wrong?Django 动态网址。我究竟做错了什么?
【发布时间】:2011-06-25 22:48:09
【问题描述】:

所以我有这个 URL 方案:

(r'^test/(?P<name>\d+)/', 'test'),

def test(request, name):
    html = "it worked"
    return HttpResponse(html)

但是,当我转到以下 URL 时,我收到 404 错误: http://127.0.0.1:8000/test/words/

我做错了什么?

【问题讨论】:

    标签: django django-views django-urls django-queryset


    【解决方案1】:

    您可能打算改用\w,例如:

    (r'^test/(?P<name>\w+)/', 'test'),
    

    \d 只匹配数字; \w 匹配任何字母数字字符。

    Python Regular Expression HOWTO A.M.古晋。

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 1970-01-01
      • 2016-07-18
      • 2019-12-23
      • 2014-06-15
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多