我有点困惑为什么在我的表单上'clickjacking middleware` trowing 属性错误。
我正在制作一个简单的应用程序来收集人工或用户信息,我面临一个小问题,有人可以帮助我并澄清此代码中的错误
来自我的Traceback的Dpaste,这是我的观点
class PersonalInfoView(FormView):
"""TODO: CreateView for PersonalInfoForm
return: TODO
"""
template_name = 'apply_to/apply_now.html'
form_class = PersonalInfoForm
success_url = 'success/'
def get(self, form, *args, **kwargs):
"""TODO: define get request
return: TODO
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
return self.render_to_response(
self.get_context_data(form=form))
def post(self, form, *args, **kwargs):
"""TODO: Post request for PersonalInfoForm
return: TODO
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid():
return self.form_valid(form)
else:
return self.form_class(form)
def form_valid(self, form, *args, **kwargs):
"""TODO: Validate form
return: TODO
"""
self.object = form.save()
return HttpResponseRedirect(self.get_success_url())
def form_invalid(self, form, *args, **kwargs):
"""TODO: handle invalid form request
return: TODO
"""
return self.render_to_response(
self.get_context_data(form=form))
网址
"""superjobs URL Configuration
the `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
examples:
function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
including another URLconf
1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.views.generic import TemplateView
from labor_apply_app.views import PersonalInfoView
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
# django-contrib-flatpages
# url(r'^apply_to/', include('labor_apply_app.urls')),
url(r'^$', 'labor_apply_app.views.index', name='index'),
url(r'^apply_now/$', PersonalInfoView.as_view()),
url(r'^success/$', TemplateView.as_view()),
# Django Allauth
url(r'^accounts/', include('allauth.urls')),
]
答案 0 :(得分:1)
您的追溯表明您还没有使用上面的视图,而是使用了表单。大概你在urls.py中分配了错误的东西。
编辑实际上问题是,当表单无效时,post方法会返回表单本身,而不是HttpResponse。
但是,你应该不定义任何这些方法。您只是复制基于类的视图已经应该为您做的事情。使您的视图实际上从CreateView继承并完全删除所有这些方法定义。