Django在Heroku上的编码错误

编程入门 行业动态 更新时间:2024-10-27 06:33:48
本文介绍了Django在Heroku上的编码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我看到一些话题,人们说使用这个命令来解决问题。

I see some topics where people say to use this command to solve the problem

heroku config:add LANG=en_US.UTF-8

我已经做了,但是不断得到编码问题,像这样

I did it already but keep getting encoding problem, like this

UnicodeEncodeError at /admin/controladoria/orgao/2/ 'ascii' codec can't encode character u'\xe7' in position 23: ordinal not in range(128)

如果我尝试运行上面的命令这是我得到的....

if I try to run the command above it is what I got....

daniel@daniel-VirtualBox: (dev *) $ heroku config:add LANG=en_US.UTF-8 Setting config vars and restarting rocky-hollows-8072... done, v11 LANG: en_US.UTF-8 daniel@daniel-VirtualBox: (dev *) $ heroku run bash Running `bash` attached to terminal... up, run.7893 ~ $ python Python 2.7.6 (default, Jan 16 2014, 02:39:37) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'ascii'

在我的机器上,用sitecustomize.py编辑我得到

at my machine, with sitecustomize.py edited i got

Python 2.7.5 (default, Mar 11 2014, 21:42:34) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'utf-8'

应该会发生吗?我知道如果我把sitecustomize.py的默认编码我没有问题。

It is supposed to happen? I know that if I put in sitecustomize.py the default encoding I don't have issues.

如何在Heroku发生这种情况?一旦我无法在Heroku上更改sitecustomize,我该如何解决?

How is that supposed to happen on Heroku? How can I solve that once I can't change sitecustomize on Heroku?

错误日志

Traceback: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 432. return self.admin_site.admin_view(view)(*args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 52. response = view_func(request, *args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 198. return view(request, *args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 29. return bound_func(*args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 99. response = view_func(request, *args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 25. return func(self, *args2, **kwargs2) File "/app/.heroku/python/lib/python2.7/site-packages/django/db/transaction.py" in inner 339. return func(*args, **kwargs) File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view 1233. self.log_change(request, new_object, change_message) File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/options.py" in log_change 614. object_repr=force_text(object), File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/encoding.py" in force_text 108. s = six.text_type(bytes(s), encoding, errors) Exception Type: UnicodeEncodeError at /admin/controladoria/orgao/2/ Exception Value: 'ascii' codec can't encode character u'\xe7' in position 23: ordinal not in range(128)

推荐答案

旧问题,但我发现同样的问题。

Old question, but I've found the same issue.

我的解决方案:我发现我的heroku的蟒蛇蜡2.x。

My solution: I've found that my heroku's python wax 2.x.

Eveything正常,因为我告诉英雄使用python 3.x(作为我的开发环境)。

Eveything went OK as I told heroku to use python 3.x (as my dev environment).

要做到这一点,只需在你的项目根目录下添加一个runtime.txt文件,然后选择正确的运行时:

To do that, just add a runtime.txt file at the root of you project, and choose the right runtime:

python-3.4.3

如下所示: devcenter.heroku/articles/python-runimes

更多推荐

Django在Heroku上的编码错误

本文发布于:2023-10-16 05:15:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Django   Heroku

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!