簡體   English   中英

/Test/ 'tuple' 處的 AttributeError object 沒有屬性 'get'

[英]AttributeError at /Test/ 'tuple' object has no attribute 'get'

當我嘗試打開 django crispy-reports 表單時,我目前看到以下錯誤。 Í 可以在網上找到的所有信息都是,我可能在不應該是逗號的地方添加了一個逗號。 但是我真的找不到。

我的播放列表表格 class

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

class PlaylistForm(forms.Form):
    name = forms.CharField(
        label='Name', 
        max_length= 64, 
        required = True)

    comment = forms.CharField(
        label='Kommentar',
        max_length= 256,
        required = False)

    def __init__(self, *args, **kwargs):
        super().__init__(args, kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id_playlist_form'
        self.helper.form_class = 'forms'
        self.helper.form_method = 'post'
        self.helper.form_action = 'test'

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

edit.html 模板

{% load crispy_forms_tags %}
{% crispy playlist_form playlist_form.helper %}

urlpatterns 條目

path('Test/', views.test, name='test')

摘錄自 views.py

from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from trackmanager.Forms.PlaylistForm import PlaylistForm

def test(request: HttpRequest)->HttpResponse:
    context = {'playlist_form': PlaylistForm()}
    return render(request, 'trackmanager/edit.html', context)

堆棧跟蹤

AttributeError at /Test/
'tuple' object has no attribute 'get'
Request Method: GET
Request URL:    
Django Version: 4.0.2
Exception Type: AttributeError
Exception Value:    
'tuple' object has no attribute 'get'
Exception Location: /usr/local/lib/python3.8/dist-packages/django/forms/widgets.py, line 263, in value_from_datadict
Python Executable:  /usr/bin/python3
Python Version: 3.8.10
Python Path:    
['/var/trackmania',
 '/usr/lib/python38.zip',
 '/usr/lib/python3.8',
 '/usr/lib/python3.8/lib-dynload',
 '/usr/local/lib/python3.8/dist-packages',
 '/usr/lib/python3/dist-packages']
Server time:    Sun, 13 Feb 2022 23:26:03 +0000
 
[...]

25          {% if not field|is_checkbox %}
26              **{% crispy_field field %}**
27          {% endif %}

[...]

def value_from_datadict(self, data, files, name):
    """
    Given a dictionary of data and this widget's name, return the value
    of this widget or None if it's not provided.
    """
    **return data.get(name)**

我找到了解決方案。 就我而言,這是一個錯誤的超級電話

如何不去做

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

怎么做

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM