Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 停留在django的URL模式上_Regex_Python 2.7_Django Urls_Django 1.3 - Fatal编程技术网

Regex 停留在django的URL模式上

Regex 停留在django的URL模式上,regex,python-2.7,django-urls,django-1.3,Regex,Python 2.7,Django Urls,Django 1.3,您好,我在django中使用以下URL模式,我想知道问题出在哪里,为什么找不到它。下面的屏幕截图显示了我的URL以及预期的URL。 请告诉我哪里出错了。请告诉我还有什么我能告诉你的来理解这个问题。我在上面看了差不多一两个小时,然后我把它贴在了stackoverflow.com上,希望我能得到一些解决方案 在此处添加URL.py: from django.conf.urls.defaults import patterns, include, url # Uncomment the next

您好,我在django中使用以下URL模式,我想知道问题出在哪里,为什么找不到它。下面的屏幕截图显示了我的URL以及预期的URL。

请告诉我哪里出错了。请告诉我还有什么我能告诉你的来理解这个问题。我在上面看了差不多一两个小时,然后我把它贴在了stackoverflow.com上,希望我能得到一些解决方案

在此处添加URL.py:

from django.conf.urls.defaults import patterns, include, url 
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'ecomstore.views.home', name='home'),
#url(r'^catalog/', 'preview.views.home'),

# url(r'^ecomstore/', include('ecomstore.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
 url(r'^admin/', include(admin.site.urls)),
 url(r'',include('catalog.urls')),
  )
然后是目录应用程序的URL.py:

from django.conf.urls.defaults import *
urlpatterns=patterns('catalog.views',
    (r'^$','index',{'template_name':'catalog/index.html'},'catalog_home'),
    (r'^category/(?P<category_slug>[-\w]+)/$','show_category',{'template_name':'catalog/category.html'},'catalog_category'),
    (r'^product/(?P<product_slug>[-_\w+])/$','show_product',{'template_name':'catalog/product.html'},'catalog_product'),


提前感谢各位。

参考我的评论:至少有一件事错了,就是你们在产品之前有一个额外的斜杠。您想要的是^product,而不是^product。这可能是全部,但从照片上很难分辨

另外,如果我错了,请纠正我,因为我已经有一段时间没有使用正则表达式了,但是[-\uw+]不是只匹配-或u或\w+

[]

将一个字符位置的方括号内的任何内容匹配一次且仅匹配一次,例如,[12]表示将目标匹配到1,如果不匹配,则将目标匹配到2,而[0123456789]表示匹配到0到9范围内的任何字符


所以你想。。。[-\uw]\w+?

您能键入urlconf的文本而不是屏幕截图吗?我看不懂,但我敢打赌它的第四行有问题。我尝试过删除它,但面临相同的问题删除什么?斜线还是直线?你需要这条线,这样django才能匹配它!你能发布你的urlconf的文本吗?答案更新了。我假设它不会通知你,因为当你更新你的问题时它不会通知我。我认为它是否与-或u或字母数字匹配并不重要,所以我认为它不会在匹配中产生问题,它可以匹配其中任何一个和多个实例。我指的是独占或。你确定它不止一个实例吗?如果将其更改为[-\uuw]\w+,会发生什么情况?我想更像是\w+[-\uw]\w+,实际上,因为下划线前后都有内容。