Django表格不会呈现

时间:2013-01-13 17:20:18

标签: django django-forms

我的表单代码:

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请求URL:

     

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:

     

回溯:文件   “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py”   在get_response中     111. response = callback(request,* callback_args,** callback_kwargs)file“/Users/judithjacques/dana/dev/pasteur/src/pasteur/views.py”in   plan_detail     13. dictionary = {'form':form})文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/shortcuts/ init 。 PY”   在渲染中     44.返回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. return 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”   在_render     134. return self.nodelist.render(context)File“/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py”   在渲染中     823. bit = self.render_node(node,context)File“/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py”   在render_node中     74. return node.render(context)File“/ Library / Frameworks / Python.framework / Version / 7.7 / lib / python2.7 / site-package / Django / template / defaultfgs.py”   在渲染中     281. return nodelist.render(context)File“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py”   在渲染中     823. bit = self.render_node(node,context)File“/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py”   在render_node中     74. return node.render(context)File“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py”   在渲染中     84. output = 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)文件“/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)文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py”   在_html_output中     171. label = bf.label_tag(label)或''File“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py”   在label_tag中     508. id_ = widget.attrs.get('id')或self.auto_id

     

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

1 个答案:

答案 0 :(得分:1)

如错误所示,{"class", "add-up"}是一组。你需要一本字典:{"class": "add-up"}