使用RoutablePageMixin时如何向页面添加自定义模板?
@route(r'^tag/(?P<tag>[-\w]+)/$')
def post_by_tag(self, request, tag, *args, **kwargs):
self.search_type = 'tag'
self.search_term = tag
self.posts = self.get_posts().filter(tags__slug=tag)
return Page.serve(self, request, *args, **kwargs)
答案 0 :(得分:3)
调用django.shortcuts.render
函数,就像在a standard Django view function中一样:
from django.shortcuts import render
@route(r'^tag/(?P<tag>[-\w]+)/$')
def post_by_tag(self, request, tag, *args, **kwargs):
# ...
posts = self.get_posts().filter(tags__slug=tag)
return render(request, 'path/to/template.html', {
'page': self,
'posts': posts,
})