/Test/ 处的 AttributeError 'tuple' 对象没有属性 '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)
我目前在尝试打开 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)