Django: Internet explorer download page content in

2019-07-24 02:09发布

问题:

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:

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

The response variable contains the HTML structure of the page, other browsers render it but, IE doesn't, why?

Thanks in advance

回答1:

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)

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.

Remove that last argument:

response = render(request, 'base_home.html', context_list)