我的 views.py 文件中有一个视图,如下所示:
def index(request):
c = {}
c.update(csrf(request))
if request.method == 'POST':
form = MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/accounts/register_success')
args = {}
args.update(csrf(request))
args['form'] = MyRegistrationForm()
return render_to_response('index.html', c), render_to_response('index.html', args)
我的 index.html 看起来像这样:
<form action="/accounts/auth/" method="post">{% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">
<input type="submit" value="login" />
</form>
<h2>Register</h2>
<form action="/accounts/register/" method="post">{% csrf_token %}
{{form}}
<input type="submit" value="Register" />
</form>
我想为 action="/accounts/auth/" 的表单渲染 c 并为 action="/accounts/register/".. 的表单渲染 args 。知道我会怎么做吗?