小编Iva*_*sov的帖子

尝试通过django默认基于文件的后端保存文件的UnicodeDecodeError

当我尝试通过默认的instance.file_field.save方法将名称中包含俄语符号的文件添加到模型实例时,我得到一个UnicodeDecodeError(ascii解码错误,不在存储后端的范围(128)中(堆栈跟踪在os上结束).如果我通过默认的python文件写这个文件open/write all right.所有文件名都在utf-8.我只在测试Gentoo时得到这个错误,在我的Ubuntu工作站上一切正常.

class Article(models.Model):
    file = models.FileField(null=True, blank=True, max_length = 300,
                            upload_to='articles_files/%Y/%m/%d/')

Traceback:
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  24.                 return view_func(request, *args, **kwargs)
File "/var/www/localhost/help/wiki/views.py" in edit_article
  338.                 new_article.file.save(fp, fi, save=True)
File "/usr/lib/python2.6/site-packages/django/db/models/fields/files.py" in save
  92.         self.name = self.storage.save(name, content)
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in save
  47.         name = self.get_available_name(name)
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in get_available_name
  73.         while self.exists(name):
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py" in exists
  196.         return os.path.exists(self.path(name))
File "/usr/lib/python2.6/genericpath.py" in exists
  18.         st = os.stat(path) …
Run Code Online (Sandbox Code Playgroud)

django unicode django-models

6
推荐指数
1
解决办法
5683
查看次数

标签 统计

django ×1

django-models ×1

unicode ×1