Django Crispy Forms TypeError:__ init __()得到了一个意外的关键字参数'instance'

时间:2014-02-01 20:55:33

标签: python django django-crispy-forms

我正在尝试在Django和Crispy表单中执行html5表单,但我得到TypeError: __init__() got an unexpected keyword argument 'instance'

forms.py

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from django import forms

class ShareImageForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ShareImageForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id-exampleForm'
        self.helper.form_class = 'blueForms'
        self.helper.form_method = 'post'
        self.helper.form_action = 'submit_survey'

        self.helper.add_input(Submit('submit', 'Submit'))

    data_center = forms.TypedChoiceField(
            label = "Please pick a region: ",
            choices = ((1, "IAD"), (2, "ORD"),
                       (3, "DFW"), (4, "HKG")),
            widget = forms.RadioSelect,
            initial = '1',
            required = True,
            )

views.py

from django.views.generic import View, CreateView, TemplateView, ListView, DetailView, DeleteView, UpdateView
from django.http import Http404, HttpResponse
from django.conf import settings
from .forms import ShareImageForm

class ShareImage(CreateView, ShareImageForm):
    template_name ="share_image.html"
    form_class = ShareImageForm
    success_url = '/'

    def form_valid(self, form):
        return super(CreateRequest, self).form_valid(form)

1 个答案:

答案 0 :(得分:3)