atascado en los patrones de URL de django

Hi I am using following URL patterns in django and I am wondering that where is problem and why it is not able to find it. Following screenshot shows my URL as well as expected URLs. enter image description here

Please tell that where I am making mistake. Please tell if some thing else I can tell to understand problem. I was looking on it for almost an hour or 2 and then I posted it on stackoverflow.com so hope I will get some solution.

Adding urls.py here:

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

Then urls.py of catalog app:

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

)

gracias de antemano chicos.

preguntado el 10 de marzo de 12 a las 01:03

can you type out the text of your urlconf instead of a screenshot? I can't read it, but I bet there's something wrong with the 4th line of it. -

I have tried removing it but facing same issue -

tried removing what? The slash, or the line? You need the line so django can match it! -

1 Respuestas

referring to my comment: at least one thing wrong is that you have an extra slash before "product". You want ^product, not ^/product. That might be all but it's a little hard to tell from the pic.

also, correct me if I'm wrong, because I haven't used regexes in a while, but doesn't [-_\w+] only match - OR _ OR \w+?

"[ ]

Match anything inside the square brackets for ONE character position once and only once, for example, [12] means match the target to 1 and if that does not match then match the target to 2 while [0123456789] means match to any character in the range 0 to 9."

http://www.zytrax.com/tech/web/regex.htm

so you'd want... [-_]\w+ ?

respondido 10 mar '12, 02:03

can you post the text of your urlconf? - Colleen

answer updated. I'm assuming it doesn't notify you, since it didn't notify me when you updated your question. - Colleen

I think it shouldn't matters if it match with - or _ or a alphanumeric so I think it shouldn't create problem in matching, it can match to any of these and more than one instances - Hafiz

I meant exclusive or. Are you sure about it being more than one instance? What happens if you change it to [-_]\w+? - Colleen

I guess more like \w+[-_]\w+, actually, because you have stuff before and after your underscore. - Colleen

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.