我有一个使用Nginx代理和uWSGI后端的成熟的Django应用。我正在尝试迁移uWSGI以使用cache2指令,并且高速缓存似乎正在导致在成功POST之后重定向的任何形式都无法重定向-只是重新加载同一页面。当我禁用缓存(或使用Django开发服务器)时,POST成功并且发生重定向。我无法想象这是cache2的预期行为-必须从缓存中排除任何带有POST的页面-因此我必须在某个地方进行错误配置。相同的代码(cache2 ini指令除外)可以与旧式缓存一起成功使用。另外,从uwsgicachetop可以看到,问题页面已成功从缓存中检索出来,因此缓存本身正在运行。是否需要添加其他一些配置以使POST成功工作?
Python 3上的Django 1.9.13
django-uwsgi-cache 1.0.1
include uwsgi_params;
uwsgi_pass unix:///opt/survey.sock;
master = true
processes = 4
no-site = true
vhost = true
enable-threads = true
vacuum = true
die-on-term = true
reload-mercy = 8
harakiri = 30
max-requests = 5000
procname-prefix = mysite_
;;; The new cache2 code section (like uWSGI advises)
cache2 = name=mycache,items=3000
; serve text/html of matched requests
route = .* cache:key=${REQUEST_URI},name=mycache
; store each successful request (200 http status code)
; in the 'mycache' cache using the REQUEST_URI as key
route = .* cachestore:key=${REQUEST_URI},name=mycache
;;; end of new code
CACHES = {
'default': {
'BACKEND': 'uwsgicache.UWSGICache',
# and optionally, if you use a different cache name
'LOCATION': 'mycache'
}
}
<form action='.' method='post' id='question_form'>{% csrf_token %}>
<input type='submit' value='Add to List' />
</form>
def choose_questions(request, slug, template_name='question.html', **kwargs):
if request.method == 'POST':
url = urlresolvers.reverse('survey_results')
return HttpResponseRedirect(url)
else:
choosequestionform = ChooseQuestionForm(request=request, slug=slug)
return render(request, template_name, locals())