报错
class PostView(CommonMixin,DetailView):
model = Post
template_name = 'blog/detail.html'
context_object_name = 'post'
正常
class PostView(DetailView):
model = Post
template_name = 'blog/detail.html'
context_object_name = 'post'
postview函数里面不继承CommonMixin就正常,继承了CommonMixin就报这个typeerror的错误
调试了源代码,没看出什么错误
[05/Aug/2018 17:35:16] "GET / HTTP/1.1" 200 482
<class 'blog.models.Post'>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Internal Server Error: /post/1/
class BaseDetailView(SingleObjectMixin, View):
"""
A base view for displaying a single object
"""
def get(self, request, *args, **kwargs):
self.object = self.get_object()
# import pdb;pdb.set_trace()
print(type(self.object))
print('x'*30)
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
def get_context_data(self, **kwargs):
"""
Insert the single object into the context dict.
"""
# import pdb;pdb.set_trace()
context = {}
if self.object:
context['object'] = self.object
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
context[context_object_name] = self.object
context.update(kwargs)
return super(SingleObjectMixin, self).get_context_data(**context)
报错 class PostView(CommonMixin,DetailView): model = Post template_name = 'blog/detail.html' context_object_name = 'post'
正常 class PostView(DetailView): model = Post template_name = 'blog/detail.html' context_object_name = 'post'
postview函数里面不继承CommonMixin就正常,继承了CommonMixin就报这个typeerror的错误
调试了源代码,没看出什么错误
报错
class PostView(CommonMixin,DetailView):
model = Post
template_name = 'blog/detail.html'
context_object_name = 'post'
正常
class PostView(DetailView):
model = Post
template_name = 'blog/detail.html'
context_object_name = 'post'
postview函数里面不继承CommonMixin就正常,继承了CommonMixin就报这个typeerror的错误
调试了源代码,没看出什么错误
已经解决