我有点困惑,因为我必须覆盖 get_context_data 方法才能使用模板上下文。urls.pyre_path( r"^post/(?P<id>\d+)/$",PostView.as_view(template_name="pages/post.html"), name="post",),views.pyclass PostView(TemplateView): template_name = 'djangoapp/pages/post.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['dataC'] = get_object_or_404(Content, Título_id="2") return context
添加回答
举报
0/150
提交
取消