我正在使用 Django Web 框架创建一个网站。 当我使用 chrome、safari、firefox 等浏览器查看它时,它可以正常工作,但如果我在 Internet Explorer 中打开页面,就会发生这种情况:
在我的views.py 中,我有以下代码:
def index(request):
context = RequestContext(request)
c_form = False
try:
c_form = request.COOKIES['cform']
except Exception:
if request.POST: c_form = foo_email(request)
context_list = {'form': c_form}
response = render(request, 'base_home.html', context_list, context)
if c_form: response.set_cookie('cform', value='1', max_age=None)
return response
response变量包含页面的HTML结构,其他浏览器可以渲染它,但是IE不会,为什么?
提前致谢
最佳答案
您正在向 render()
传递无效参数。来自 docs ,它需要以下参数:
render(request, template_name, context=None, content_type=None, status=None, using=None)
您将 context
传递给 content_type
参数,这在某种程度上不会完全破坏,但最终导致响应不包含 text/html
内容类型。因此 IE 会尝试下载它。
删除最后一个参数:
response = render(request, 'base_home.html', context_list)
关于python - Django:Internet Explorer 下载页面内容而不是渲染它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069717/