G
G
Grigory Dikiy2016-02-21 09:26:13
Django
Grigory Dikiy, 2016-02-21 09:26:13

Wysiwyg django encoding issues when uploading to server?

Good day. I decided to implement the wysiwyg editor on my site. Everything is fine, the text is edited as intended, but when I upload the file to the server I get an error.

Internal Server Error: /redactor/upload/image/
Traceback (most recent call last):
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/redactor/views.py", line 48, in dispatch
    **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/views/generic/edit.py", line 222, in post
    return self.form_valid(form)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/redactor/views.py", line 66, in form_valid
    uploader.save_file()
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/redactor/handlers.py", line 47, in save_file
    self.get_file())
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/files/storage.py", line 53, in save
    name = self.get_available_name(name, max_length=max_length)
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/files/storage.py", line 89, in get_available_name
    while self.exists(name) or (max_length and len(name) > max_length):
  File "/data/mysite/venv/mysite/local/lib/python2.7/site-packages/django/core/files/storage.py", line 294, in exists
    return os.path.exists(self.path(name))
  File "/data/mysite/venv/mysite/lib/python2.7/genericpath.py", line 18, in exists
    os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 35-40: ordinal not in range(128)
[21/Feb/2016 06:14:17] "POST /redactor/upload/image/ HTTP/1.1" 500 17669

models:
@python_2_unicode_compatible
class Article(models.Model):
    class Meta:
        db_table = 'article'

    article_title = models.CharField(max_length=200)
    article_slug = models.SlugField(max_length=100, unique=True)
    article_text = RedactorField(verbose_name=u'Text')
    article_date = models.DateTimeField()
    article_likes = models.PositiveIntegerField(default=0, editable=False)
    article_category = models.ManyToManyField(Category)

    def __str__(self): return self.article_title
    def __unicode__(self): return self.article_title

admin:
class ArticleAdminForm(forms.ModelForm):
    class Meta:
        model = Article
        fields = '__all__'
        widgets = {
           'article_text': RedactorEditor(),
        }

class ArticleAdmin(admin.ModelAdmin):
    list_filter = ['article_date', 'article_category']
    list_display = ['article_title', 'article_date']
    search_fields = ['article_title']
    prepopulated_fields = {'article_slug': ('article_title',)}
    form = ArticleAdminForm

settings:
REDACTOR_OPTIONS = {'lang': 'en'}

REDACTOR_UPLOAD = 'uploads/'

I would be grateful for help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question