Answer the question
In order to leave comments, you need to log in
Why is get_absolute_url not output in template?
Hello. There was a problem rendering get_absolute_url in template.
Here is my models.py:
class Category(models.Model):
category_name = models.CharField(max_length=100)
def __unicode__(self):
return self.category_name
class Post(models.Model):
title = models.CharField(max_length=255)
datetime = models.DateField(u'Дата публикации')
content = RichTextField()
category = models.ForeignKey(Category)
slug = models.SlugField(max_length=255, blank=True)
def save(self, *args, **kwargs):
if not self.id:
self.slug = translit.slugify(self.title)
super(Post, self).save(*args, **kwargs)
def __unicode__(self):
return self.title
def get_absolute_url(self):
return '/blog/%i/' % self.id
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
<a href="/blog/1/">Первый пост</a>
def get_absolute_url(self):
return '/blog/%i/' % self.slug)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question