不上传图片(django-wysiwyg-redactor)

时间:2014-12-04 20:03:18

标签: django django-admin wysiwyg

我下载了django-wysiwyg-redactor

并按照有关如何使用它的说明进行操作。 但是当我选择要上传的图片时,它无法上传。没有错误。 它有什么问题?

这是我的文章模型: 来自django.db导入模型 来自redactor.fields导入RedactorField

在此处创建模型。

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

    article_title = models.CharField(max_length=200)
    article_text = RedactorField(
        verbose_name=u'Text',
        redactor_options={'lang': 'en', 'focus': 'true'},
        upload_to='tmp/',
        allow_file_upload=True,
        allow_image_upload=True
    )
    article_date = models.DateTimeField()
    article_likes = models.IntegerField(default=0)

admin.py

from django.contrib import admin
from redactor.widgets import RedactorEditor
from article.models import Article
from django import forms

class EntryAdminForm(forms.ModelForm):
    class Meta:
        model = Article
        widgets = {
           'article_text': RedactorEditor(),
        }

class EntryAdmin(admin.ModelAdmin):
    form = EntryAdminForm
    fields = ['article_title', 'article_text', 'article_date']

admin.site.register(Article, EntryAdmin)

上一个代码行:admin.site.register(Article, EntryAdmin)略有变化,因为正如指令所说,它必须是admin.site.register(EntryAdminForm, EntryAdmin),但在这种情况下,会出现错误:'ModelFormMetaclass' object is not iterable

2 个答案:

答案 0 :(得分:0)

不要在EntryAdminForm上指定小部件。 RedactorField将使用正确的配置生成小部件。

class EntryAdminForm(forms.ModelForm):
    class Meta:
        model = Article

答案 1 :(得分:0)

这是我如何运作

<强> models.py

from redactor.fields import RedactorField

在我的模特中

text = RedactorField(verbose_name=u'Text')

<强> settings.py

INSTALLED_APPS = (
'redactor',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)

REDACTOR_OPTIONS = {'lang': 'en'}
REDACTOR_UPLOAD = 'static/'

<强> urls.py

url(r'^redactor/', include('redactor.urls')),

<强> admin.py

from django import forms
from redactor.widgets import RedactorEditor

class EntryAdminForm(forms.ModelForm):
class Meta:
    model = Post
    widgets = {
       'text': RedactorEditor(),
    }
    fields = '__all__'

class EntryAdmin(admin.ModelAdmin):
    form = EntryAdminForm