Django:Internet Explorer下载页面内容而不是呈现页面内容 [英] Django: Internet explorer download page content instead of rendering it
问题描述
我正在使用Django Web Framework创建一个网站.当我使用chrome,safari,firefox等浏览器查看它时,它可以正常工作,但是如果我在Internet Explorer中打开该页面,则会发生这种情况:
I am creating a website using Django Web Framework. When I view it with browsers like chrome, safari, firefox, etc it work properly, but if I open the page in Internet Explorer this happens:
在我的views.py中,我有以下代码:
In my views.py I have this code:
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
响应变量包含页面的HTML结构,其他浏览器将其呈现,但是IE却不显示,为什么?
The response variable contains the HTML structure of the page, other browsers render it but, IE doesn't, why?
预先感谢
推荐答案
您正在将无效的参数传递给 render()
.从 docs 中,它采用以下参数:
You are passing invalid arguments to render()
. From the docs, it takes the following arguments:
render(request, template_name, context=None, content_type=None, status=None, using=None)
您要将 context
传递给 content_type
自变量,该自变量不会完全中断,但最终会导致响应中不包含 text/html
内容类型.因此,IE尝试下载它.
You are passing context
to the content_type
argument, which somehow doesn't break altogether, but ends up in the response not containing a text/html
content type. Hence IE tries to download it.
删除最后一个参数:
response = render(request, 'base_home.html', context_list)
这篇关于Django:Internet Explorer下载页面内容而不是呈现页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!