[Deprecation] Resource requests whose URLs contained both removed whitespace (`\n`, `\r`, `\t`) characters and less-than characters (`<`) are blocked. Please remove newlines and encode less-than characters from places like element attribute values in order to load these resources. See https://www.chromestatus.com/feature/5735596811091968 for more details.
今天用django做博客时候报了这么一个错误。
边查边试,最后定位到{{ article.body|safe | slice:'200' }}这句代码的slice:'200'造成的,因为截取文章时有某对标签只截取了一个,漏掉了一个标签。
最后换了个语法:
{{ article.body|safe | truncatechars_html:'100' }}
利用truncatechars_html过滤器截断,不会漏掉标签。
更新:
或者用django的striptags过滤器,去掉所有标签,只保留文本。这样做文章摘要的时候更合理。
{{ article.body|striptags | slice:'100' | safe }}
官方文章:https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#truncatechars-html