zoukankan      html  css  js  c++  java
  • 【菜鸟笔记】记一次django无法正常在ie和edge浏览器渲染html页面

    如图所示,django无法渲染html显示成下载文件了

    一步一步的从render ==》HttpResponse ==》HttpResponseBase 找到

    即django文件夹下的http文件夹内的response.py文件

    class HttpResponseBase:
        """
        An HTTP response base class with dictionary-accessed headers.
    
        This class doesn't handle content. It should not be used directly.
        Use the HttpResponse and StreamingHttpResponse subclasses instead.
        """
    
        status_code = 200
    
        def __init__(self, content_type=None, status=None, reason=None, charset=None):
            # _headers is a mapping of the lower-case name to the original case of
            # the header (required for working with legacy systems) and the header
            # value. Both the name of the header and its value are ASCII strings.
            self._headers = {}
            self._closable_objects = []
            # This parameter is set by the handler. It's necessary to preserve the
            # historical behavior of request_finished.
            self._handler_class = None
            self.cookies = SimpleCookie()
            self.closed = False
            if status is not None:
                try:
                    self.status_code = int(status)
                except (ValueError, TypeError):
                    raise TypeError('HTTP status code must be an integer.')
    
                if not 100 <= self.status_code <= 599:
                    raise ValueError('HTTP status code must be an integer from 100 to 599.')
            self._reason_phrase = reason
            self._charset = charset
            if content_type is None:
                content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                                   self.charset)
            self['Content-Type'] = content_type

    需要在django项目下的settings.py文件添加下面内容

    DEFAULT_CONTENT_TYPE = 'text/html'

    为了保证Content-Type的值返回正常的值

    将response.py的

            self['Content-Type'] = content_type

    更改成

            self['Content-Type'] = content_type if type(content_type) ==  type('') else 'text/html; charset=utf-8'

    然后重新dajngo服务

    成功渲染html文件

  • 相关阅读:
    linux 添加环境变量(php为例)
    composer install Your requirements could not be resolved to an installable set of packages
    pytesseract 验证码识别
    mac crontab时间断内随机时间执行定时任务
    Mac使用crontab来实现定时任务
    安居客滑动验证码识别
    jQuery图片点击预览遮罩层,再点击关闭效果
    linux系统必学-部分链接
    JavaScript概念总结:作用域、闭包、对象与原型链
    Web前端性能优化全攻略
  • 原文地址:https://www.cnblogs.com/wananonline/p/10677945.html
Copyright © 2011-2022 走看看