gpt4 book ai didi

python - Django Crispy Forms 类型错误 : __init__() got an unexpected keyword argument 'instance'

转载 作者:行者123 更新时间:2023-11-30 23:28:43 27 4
gpt4 key购买 nike

我正在尝试在 Django 和 Crispy 表单中创建 html5 表单,但我收到 TypeError: __init__() got an Unexpected keywords argument 'instance':

表单.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,
)

View .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)

最佳答案

关于python - Django Crispy Forms 类型错误 : __init__() got an unexpected keyword argument 'instance' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21503553/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com