Not a valid regular expression error in Django -
please see urlpatterns given below, following error when try run program...
improperlyconfigured @ / "^product/(?p<product_slug> [-\w]+)/$" not valid regular expression: unexpected end of pattern request method: request url: http://127.0.0.1:8000/ django version: 1.5.1 exception type: improperlyconfigured exception value: "^product/(?p<product_slug> [-\w]+)/$" not 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
urls.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'), )
views.py
def index(request,template_name="catalog/index.html"): page_title = 'music instruments , sheet music 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))
you need capitalize ?p
, so:
r'^product/(?p<product_slug> [-\w]+)/$'
Comments
Post a Comment