Add Address
{% csrf_token %}
...
Update values
{% csrf_token %}
...
Address
...display...
我view.py是:
def property(request):
if request.method == 'POST':
if '_update' in request.POST:
...update values...
elif '_add_add' in request.POST:
...add addres....
Context = {"name_for_template":"value"}
else:
... graph default values...
Context = {"name_for_template":"value"}
return render(request, 'address.html', context)
当不存在POST和简单的GET(就像被重定向到页面),我在上下文中得到了一个CSRF错误(并且它要求我使用request_context)。是否可以(以及如何)自动发送GET的默认上下文,并发送POST的不同上下文而不引发CSRF错误?
2016-11-07
H C
+0
的函数必须返回:上下文= {}。返回渲染(请求,'address.html',上下文)。之后,如果您有发布请求,请在上下文中添加价值。上下文= {“name_for_template”:“value”} –
+0
我更新了问题。我确定了什么是上下文。问题是关于通过GET发送上下文时获得的CSRF错误。当我通过POST发送上下文时,该页面正常工作。 –
+0
在渲染功能,这是第3参数必须要发送到模板的背景下, '高清财产(请求): 上下文= {} 如果request.method ==“POST”: 如果“_Update”在request.POST: ...更新值... ELIF在request.POST '_add_add': ......添加ADDRES .... 背景[ “name_for_template”] = “值” 其他: ...图形默认值... context [“name_for_template”] =“value” return render(request,'address.html',cont ext)' 如果不起作用,请发布您的整个代码。 –