Python 在Django中通过URL传递参数时找不到页面

Python 在Django中通过URL传递参数时找不到页面,python,regex,django,Python,Regex,Django,我怀疑这可能与我设计正则表达式的方式有关,因为当我尝试转到时,会得到以下输出:例如 Django使用gfp.URL中定义的URLconf,按以下顺序尝试了这些URL模式: ^recipes/$ ^recipes/category/(?P<category>\d+)/$ ^recipes/search/(?P<term>\d+)/$ ^recipes/view/(?P<slug>\d+)/$ ^admin/ 我怀疑这是我的正则表达式,有人能解释一下它的错误吗?

我怀疑这可能与我设计正则表达式的方式有关,因为当我尝试转到时,会得到以下输出:例如

Django使用gfp.URL中定义的URLconf,按以下顺序尝试了这些URL模式:

^recipes/$
^recipes/category/(?P<category>\d+)/$
^recipes/search/(?P<term>\d+)/$
^recipes/view/(?P<slug>\d+)/$
^admin/
我怀疑这是我的正则表达式,有人能解释一下它的错误吗?我在一些url正则表达式上看到了/w(?),但在Django tuorial中没有用到:

“^recipes/search/(?p\d+/$”
匹配
/recipes/search/123456/
“^recipes/search/(?P[-\w]+)/$”
可能是您所需要的。(用连字符更新)

查看文档以了解“\d”、“w”和其他的含义。

^recipes/search/(?p\d+/$”匹配
/recipes/search/123456/
“^recipes/search/(?P[-\w]+)/$”
可能是您所需要的。(用连字符更新)


查看文档以了解“\d”、“w”和其他内容的含义。

您可以使用
recipe/search
的URL模式只允许搜索词使用数字(
\d
)。将其更改为
\w
,您应该会做得很好。

您的URL模式对于
配方/搜索
只允许数字(
\d
)作为搜索词。将其更改为
\w
,您应该会很好。

谢谢!那么\d numeric和\w char还是varchar?谢谢!那么\d numeric和\w char还是varchar呢?谢谢!有效的方法是\d数字和\w字符?我怎么能允许连字符行这样做,因为它看起来\w将不接受这样做?我想\d也没有?
\w
通常是任何字母数字字符和下划线,所以我应该只将我的slug存储为带有下划线的名称?django中的slugify字段使用----dashesIt,当slug包含连字符时,它是ok的。只需使用我提供的regexp
[-\w]+
也谢谢!有效的方法是\d数字和\w字符?我怎么能允许连字符行这样做,因为它看起来\w将不接受这样做?我想\d也没有?
\w
通常是任何字母数字字符和下划线,所以我应该只将我的slug存储为带有下划线的名称?django中的slugify字段使用----dashesIt,当slug包含连字符时,它是ok的。只需使用我提供的regexp
[-\w]+
urlpatterns = patterns('',
url(r'^recipes/', 'main.views.recipes_all'),
url(r'^recipes/category/(?P<category>\d+)/$', 'main.views.recipes_category'),
url(r'^recipes/search/(?P<term>\d+)/$', 'main.views.recipes_search'),  
url(r'^recipes/view/(?P<slug>\d+)/$', 'main.views.recipes_view'),
def recipes_all(request):
    return HttpResponse("this is all the recipes")

def recipes_category(request, category):
    return HttpResponse("this is the recipes category % s" % (category))

def recipes_search(request, term):
    return HttpResponse("you are searching % s in the recipes" % (term))

def recipes_view(request, slug):
    return HttpResponse("you are viewing the recipe % s" % (slug))