Django Slug Not Working In get_absolute_url -


whats wrong code? get_absolute_url blank when rendered in template, means it's failing somewhere.

i suspect it's slug first time have tried use within django:

thanks

model:

class entry(models.model):     title = models.charfield(max_length=200)     slug = models.slugfield(max_length=255, unique=true)      def get_absolute_url(self):        return reverse("entrydetail", kwargs={"slug": self.slug}) 

url:

 url(r'^entry/(?p<slug>[^\.]+).html',                            blog_views.entrydetail.as_view(),                            name='blog_entry'), 

view:

class entrydetail(detailview):      context_object_name = 'entry'     template_name = "blog.entry.html"     slug_field = 'slug'      def get_object(self):         return get_object_or_404(entry, url=self.slug_field) 

based on @peter deglopper stated in comments: looks trying absolute url using class based view. don't use reverse here, instead should give urls name, , refer that.

for example how should look:

model

@models.permalink def get_absolute_url(self):    return 'blog_entry', (), {'slug': self.slug} 

urls

url(r'^entry/(?p<slug>[^\.]+).html',      blog_views.entrydetail.as_view(),        name='blog_entry'), 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -