【问题标题】:Django: Internet explorer download page content instead of rendering itDjango:Internet Explorer 下载页面内容而不是渲染它
【发布时间】:2019-05-08 22:31:22
【问题描述】:

我正在使用 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 没有,为什么?

提前致谢

【问题讨论】:

    标签: python html django internet-explorer


    【解决方案1】:

    您将无效参数传递给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)
    

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 2016-07-01
      • 2016-09-25
      • 2014-04-20
      • 1970-01-01
      • 2017-08-10
      相关资源
      最近更新 更多