0
我在views.py
类似的东西:如何在Django中获取url变量?
class CommentMixin(object):
def get_context_data(self, **kwargs):
context = super(MenuMixin, self).get_context_data(**kwargs)
context['comments'] = Comments.objects.filter(post=xxxxxxxxxxxxx).order_by('-pub_date')
return context
...
class PostDetailView(CommentMixin, generic.DetailView):
model = models.Post
PostDetail = PostDetailView.as_view()
PostList = PostList.as_view()
和comment.html
片段:
{% for comment in comments %}
<article class="uk-comment">
<header class="uk-comment-header">
<img class="uk-comment-avatar" src="{%gravatar_url comment.email%}" alt="Avatar">
<h4 class="uk-comment-title">{{comment.author}}</h4>
<div class="uk-comment-meta">Dodano dnia {{comment.pub_date}}</div>
</header>
<div class="uk-comment-body">{{comment.content}}</div>
</article>
片段的urls.py
:
url(r'^post/(?P<slug>[\w\-_]+)/$', 'page.views.PostDetail', name='post-detail'),
我想后更换xxxxxxxxxxxxx
在该页面上。 URL格式正在寻找这样的:
http://localhost:8000/post/my-post-name/
你可以做'self.request.POST' – karthikr
什么是urls.py入门? –