code标签无法渲染html,【菜鸟笔记】记一次django无法正常在ie和edge浏览器渲染html页面-站长资讯中心...

c4468b3f4df77e96b0a416fa2a870fba.png

b240954f504bce90b593986876dc7edd.png

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

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

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

classHttpResponseBase:"""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=Falseif status is notNone: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=charsetif content_type isNone:

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服务

c01bf911ec0e8176a32480e3274ba6a4.png

成功渲染html文件

原文链接:https://www.cnblogs.com/canmeng/p/10677945.html

如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值