python - Django:尝试读取模板 500.html 时出现 UnicodeDecodeError

标签 python html django amazon-web-services django-templates

我正在尝试使用 AWS Elastic Beanstalk 将我的 django 应用程序部署到生产环境。在我的暂存环境中,我有 DEBUG=True,一切都很好,但是当 DEBUG=False 时,我在尝试读取模板/时收到错误 UnicodeDecodeError首页/docker/code/django-app/templates/500.html

这是我的 500.html 模板:

{% extends "base.html" %} 
{% load i18n %}

{% block title_html %}{% trans 'Server error (500)' %}{% endblock %}

{% block content %} 
    <h1>{% trans 'Server Error <em>(500)</em>' %}</h1> 
    <p>
        {% trans "There has been an error. It's been reported to the site administrators and should be fixed shortly. Thank you for your patience." %}
    </p>

{% endblock %}

最佳答案

可能是你的500模板没有以UTF-8编码保存。由于您使用的是 Komodo Edit,请尝试将其编码更改为 utf8:

Load the file -> right-click on the tab -> properties & settings -> File Preferences -> File Settings/Encodings

关于python - Django:尝试读取模板 500.html 时出现 UnicodeDecodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27718720/

相关文章:

python - 解释字符串 bool 测试结果

python - Django/Python 中的解码不反转 unicode 编码

python - CSRF token 丢失或不正确(我知道,之前已被问过!)

django - 使用 Django 用户管理员使电子邮件字段独一无二

python - 如何在pycharm中相应选择python版本?

python - 为什么 `script.py <(cat *.gz)` 在 python 2 中可以与 subprocess.Popen 一起使用,但在 python 3 中却不能?

php - 如何在mysql中导入CSV?

Android 上的 HTML 右边缘溢出

python - 定义一次绘图选项并为多个子图调用它们

javascript - 如何在 <div> HERE <div/> 中循环