【问题标题】:Django Form has no attribute getDjango Form 没有属性 get
【发布时间】:2022-01-23 20:38:46
【问题描述】:

我有一个表格

class EntryForm(forms.ModelForm):

    status = forms.ChoiceField(
        choices=Maca.Status.choices,
        widget=forms.RadioSelect(attrs={"class": "radio-ul"}),
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    class Meta:
        model = Entry
        fields = ["status", "commission"]

我尝试使用基于类的视图来更新对象

    def post(self, request, *args, **kwargs):
       entries = UsersProductConfig.objects.get(pk=request.POST["object_id"])
       maca = EntryForm(request.POST or None, instance=entries)
       if maca.is_valid():
          maca.save()
       return maca

但我收到以下错误

'EntryForm' object has no attribute 'get'

【问题讨论】:

    标签: python django


    【解决方案1】:

    基于类的视图不是我的强项,我没有你的完整视图,但一种可能是你没有 get() 方法来检查获取请求。我在想类似的东西,

    def get(self, request):
       maca = EntryForm()
       return maca
    

    来源:Django - 'ContactForm' object has no attribute 'get'

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 2017-07-06
      • 2017-10-14
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多