我想在Django渲染中傳遞多個變量。其中一個是csrf標記,另一個是我的表單(因爲我需要表單中的錯誤)。出於某種原因,它們都不起作用。任何幫助?Django在渲染中傳遞多個變量
這裏是模板:
<form class = "navbar-form" action="{% url "registry.views.register" %}" onsubmit=" return ClickButton(); " method= "POST" >
{% csrf_token %}
{{ form.errors}} {{ form.non_field_errors }}
這裏是view.py:
高清登記(請求):
form_save = RegisterationForm()
if request.method == 'POST':
form = RegisterationForm(request.POST)
if form.is_valid():
user_info={}
user_info['username'] = form.cleaned_data['username']
user_info['password'] = form.cleaned_data['password']
form.save(user_info)
return render_to_response('register_success.html',user_info)
else:
form_save = form
return render_to_response('register.html',{'csrf':csrf(request),'locals':locals()})