【问题标题】:Django Named groups not matchingDjango命名组不匹配
【发布时间】:2013-12-07 13:14:42
【问题描述】:

这些是我的文件:

urls.py:

from django.conf.urls import patterns, include, url
from eiris_wipro.views import *   

urlpatterns = patterns('',
                   (r'^hello/$',hello),
                   (r'^articles/(?P<collection>)/$', restusers),
)

views.py: 从 django.http 导入 HttpResponse

def hello(request):
    return HttpResponse("Hello new world!")

def restusers(request, collection='smthn'):
    print 'Collection', collection
    return HttpResponse(collection)

当我尝试点击http://127.0.0.1:8000/articles/smthn/ 时,我收到404 错误!!

我应该遗漏一些非常基本的东西。那可能是什么?

【问题讨论】:

  • 您的 urlpatterns 不包括 /smthn//articles/smthn/
  • @alko:哎呀错字了。谢谢。固定

标签: python django django-urls


【解决方案1】:

你没有给模式任何东西来捕捉。应该是:

r'^articles/(?P<collection>\w+)/$'

假设您要捕获任意数量的字母数字字符。

【讨论】:

    猜你喜欢
    • 2014-10-17
    • 1970-01-01
    • 2019-01-18
    • 2015-12-18
    • 2012-01-06
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多