views.py:
def index(request):
articles = Main.objects.all()
login_form2 = LoginForm2()
ResponseDict = {"active_page_id": "index", "articles": articles, "login_form2": login_form2}
return render_to_response("index.html", ResponseDict,
context_instance = RequestContext(request))
forms.py:
class LoginForm2(forms.Form):
login2 = forms.CharField(max_length=100)
pwd2 = forms.CharField(max_length=100, widget=forms.PasswordInput)
模板:
<div id="col-in">
<h3><span>Authorization</span></h3>
<form action="" method="POST">
{% csrf_token %}
<div class="error" id="error">{{ auth_error }}</div><br />
{{ login_form2.login2 }}
{{ login_form2.pwd2 }}
<input type="submit" name="auth_submit" value="Submit">
</form>
</div>
当我使用此模板进入页面时,“login2”和“pwd2”字段已经填满(可能是Django admin的auth数据)。至于我,这里发生了一些黑魔法。如何在页面上显示这些值以及如何正确显示身份验证表单?