URL
path('<int:year>/<slug:post>/',views.post_detail, name='post_detail'),
VIEW
def post_detail(request, year, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,)return render(request,
'blog/post/detail.html',
{'post': post})
TEMPLATE
{% extends "blog/base.html" %}
{% block title %}{{ post.title }}{% endblock %}{% block content %}
<h1>{{ post.title }}</h1>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|linebreaks }}
{% endblock %}
Canonical URL
def get_absolute_url(self):
return reverse('blog:post_detail', args=[self.publish.year, self.slug]
TEMplate DIrectory
PROJECT/APP/template/blog/detail.html
-- regards
Tribhuvan Kishor Bhaskar
Tribhuvan Kishor Bhaskar
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACiphSX2LQ-oL0OwktHhLqCFwqqPwVwFagCaGX2rNTiBdxOa%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment