python - Pass slug field to url -
i'm trying create detailed view of model: product.
but, i'm not getting how pass slug-field url.
this detailed view:
def single_product(request): product = get_object_or_404(prods, slug=slug) return render_to_response('teste.html', locals(), context_instance=requestcontext(request))
this model:
class product(models.model): name = models.charfield(max_length=500) #inserir slugify na url produto slug = models.slugfield(max_length=500) category = models.foreignkey(category) image = models.imagefield(upload_to='thumbs/') created = models.datetimefield(auto_now=true, auto_now_add=false) updated = models.datetimefield(auto_now=true, auto_now_add=true)
and value of slug product 1:'kinect-xbox-360' when try run: [localhost]/kinect-xbox-360/ message:
typeerror @ /kinect-xbox-360/ 'str' object not callable
you need add slug appropriate url in urls.py
. passed parameter in view:
urls.py
... url(r'^product/(?p<slug>[\w-]+)/$', 'views.single_product', name='detail'), ...
views.py
def single_product(request, slug): product = get_object_or_404(prods, slug=slug) return render_to_response('test.html', locals(), context_instance=requestcontext(request))
Comments
Post a Comment