请参阅下面给出的我的 urlpatterns,当我尝试运行程序时出现以下错误...
ImproperlyConfigured at /
"^product/(?p<product_slug> [-\w]+)/$" is not a valid regular expression: unexpected end of pattern
Request Method:
GET
Request URL:
http://127.0.0.1:8000/
Django Version:
1.5.1
Exception Type:
ImproperlyConfigured
Exception Value:
"^product/(?p<product_slug> [-\w]+)/$" is not a valid regular expression: unexpected end of pattern
Exception Location:
C:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\core\urlresolvers.py in regex, line 178
Python Executable:
C:\Python27\python.exe
网址.py
urlpatterns = patterns('ecomstore.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'),
)
视图.py
def index(request,template_name="catalog/index.html"):
page_title = 'Music instruments and Sheet music for musicians'
return render_to_response(template_name,locals(),context_instance=RequestContext(request))
def show_category(request,category_slug,template_name="catalog/category.html"):
print 'In Catalog views|category_slug=', category_slug
c = get_object_or_404(Category,slug=category_slug)
products = c.product_set.all()
page_title = c.name
meta_keywords = c.meta_keywords
meta_description = c.meta_description
return render_to_response(template_name,locals(),context_instance=RequestContext(request))
def show_product(request,product_slug,template_name="catalog/product.html"):
p = get_object_or_404(Product, slug=product_slug)
categories = p.categories.filter(is_active=True)
page_title = p.name
meta_keywords = p.meta_keywords
meta_description = p.meta_description
return render_to_response(template_name,locals(),context_instance=RequestContext(request))