我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.views.generic.CreateView()。
def _get_object(self, cls, attr): # CreateView supplies a defect get_object method and has to be excluded if hasattr(self, 'get_object') \ and not isinstance(self, generic.CreateView): try: object = self.get_object() if isinstance(object, cls): return object if hasattr(object, attr): return getattr(object, attr) except Http404: return None except AttributeError: return None return None
def get_success_url(self): # XXX: This is unused but enforced by `CreateView` return reverse('pootle-user-stats', kwargs=self.kwargs)
def post(self, request, *args, **kwargs): try: self.object = self.get_object() success_url = self.get_success_url() self.object.deleted = False self.object.save() return HttpResponseRedirect(success_url) except: pass return super(CreateView, self).post(request, *args, **kwargs)