1

我的表单代码:

class PlanForm(forms.Form):
    a = forms.CharField(widget=forms.TextInput(attrs={"class", "add-up"}))
    b = forms.CharField(widget=forms.TextInput(attrs={"class", "add-up"}))

    class Media:
        javascript=('test.js', )

我的查看代码:

def plan_detail(request):
    if request.method == "POST":
        return render(request=request,
                  template_name='pasteur/plan_detail.html',
                      dictionary={ 'message': 'This was a post request. WTF!' })
    else:
        return render(request=request,
                  template_name='pasteur/plan_detail.html',
                      dictionary={ 'form': PlanForm() })

堆栈跟踪:

环境:

请求方法:GET 请求地址:

Django 版本:1.4 Python 版本:2.7.2 已安装的应用程序:('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib .messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'south', 'pasteur') 已安装的中间件: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware'、'django.middleware.csrf.CsrfViewMiddleware'、'django.contrib.auth.middleware.AuthenticationMiddleware'、'django.contrib.messages.middleware.MessageMiddleware')

模板错误:在模板 /Users/judithjacques/dana/dev/pasteur/src/pasteur/templates/pasteur/plan_detail.html 中,第 8 行的错误“set”对象没有属性“get”1:

回溯:get_response 111 中的文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py”。 response = callback(request, *callback_args, **callback_kwargs) 文件 "/Users/judithjacques/dana/dev/pasteur/src/pasteur/views.py" in plan_detail 13. dictionary={ 'form': form }) 文件 "/Library/Frameworks/Python.framework/版本/2.7/lib/python2.7/site-packages/django/shortcuts/init.py" 在渲染 44. return HttpResponse(loader.render_to_string(*args, **kwargs), File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template /loader.py”在 render_to_string 176. 返回 t.render(context_instance) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py”渲染 140. return self._render(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.渲染 823 中的 nodelist.render(context) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py”。bit = self.render_node(node ,context)文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py”在render_node 74。返回node.render(context)文件“/Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/defaulttags.py”在渲染281。返回nodelist.render(context)文件“/Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/site-packages/django/template/base.py”在渲染 823.bit = self.render_node(node, context) 文件”/Library/Frameworks/Python.framework/Versions/ 2.7/lib/python2.7/site-packages/django/template/debug.py”在 render_node 74. 返回 node.render(context) 文件”/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py”在渲染 84. 输出 = self.filter_expression.resolve(context) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site -packages/django/template/base.py" 在解析 571.obj = self.var.resolve(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ django/template/base.py" 在解析 721. value = self._resolve_lookup(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base .py”在_resolve_lookup 772. current = current() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py”在as_ul 229。errors_on_separate_row = False) _html_output 171 中的文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py”。label = bf.label_tag(label) 或'' label_tag 508 中的文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py”。id_ = widget.attrs.get('id' ) 或 self.auto_idget('id') 或 self.auto_idget('id') 或 self.auto_id

异常类型:/pasteur/plan/create/ 处的 AttributeError 异常值:'set' 对象没有属性 'get'

4

1 回答 1

1

正如错误所说,{"class", "add-up"}是一个集合。你需要一本字典:{"class": "add-up"}.

于 2013-01-13T17:23:14.973 回答