从我的数据库中获取数据后,我试图在表单中显示一些复选框。我有一些字段可以设置是否公开。该复选框始终“未选中”。
我的课:
class PrivacyForm(forms.Form):
geburtsdatum=forms.CheckboxInput()
strasse=forms.CheckboxInput()
plz=forms.CheckboxInput()
ort=forms.CheckboxInput()
land=forms.CheckboxInput()
fon=forms.CheckboxInput()
我的方法:
@login_required
def edit_privacy(request,template_name='user/edit_privacy.html'):
user=Users.objects.get(id_u=request.user.id)
if request.method=='POST':
form=PrivacyForm(request.POST)
if form.is_valid():
#
render_to_response('user/public_profil.html',{'profil':user},context_instance=RequestContext(request))
else:
msg="make sure all fields are entered and valid"
else:
#form
form=PrivacyForm()
msg="Select what you want to be public"
return render_to_response(template_name,{'form':form,'profil':user,'msg':msg},context_instance=RequestContext(request))
和我的表格:
{% extends "home/portal.html" %}
{% block body %}
<h3>::::: PRIVATSPHÄRE :::::</h3>
{{msg}}
<form id="formSearch" action="/user/privacy/" method="post">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Speichern" class="button"/>
</form>
{% endblock %}
任何帮助,将不胜感激。谢谢 :)