我的表單代碼:Django表單將不會呈現
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() })
堆棧跟蹤:
environment:
Request Method: GET Request URL:
Django Version: 1.4 Python Version: 2.7.2 Installed Applications: ('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') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')
Template error: In template /Users/judithjacques/dana/dev/pasteur/src/pasteur/templates/pasteur/plan_detail.html, error at line 8 'set' object has no attribute 'get' 1 :
Traceback: File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in 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 }) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/shortcuts/init.py" in render 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" in render_to_string 176. return t.render(context_instance) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render 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.nodelist.render(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render 823. bit = self.render_node(node, context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/defaulttags.py" in render 281. return nodelist.render(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in render 823. bit = self.render_node(node, context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/debug.py" in render 84. output = self.filter_expression.resolve(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in resolve 571. obj = self.var.resolve(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in resolve 721. value = self._resolve_lookup(context) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup 772. current = current() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py" in as_ul 229. errors_on_separate_row = False) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py" in _html_output 171. label = bf.label_tag(label) or '' File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/forms.py" in label_tag 508. id_ = widget.attrs.get('id') or self.auto_id
Exception Type: AttributeError at /pasteur/plan/create/ Exception Value: 'set' object has no attribute 'get'