如何安装 django-ckeditor?

发布于 2024-10-08 17:17:24 字数 2133 浏览 3 评论 0原文

在 Stack Overflow 上有两个关于这个编辑器的问题,但没有人回答!

所以我问如何将此 Django 包安装到我的项目中? 我已经按照这些步骤进行操作,没有错误,没有任何错误,但是仍然形式保持不变。为什么??

编辑:继承者模型

from datetime import datetime

from django.db                import models
from django.utils.translation import ugettext_lazy as _, ugettext
from ckeditor.fields          import RichTextField

class Newsletter(models.Model):

    title = models.CharField(
        _(u'Title'),
        max_length=200,
        help_text=_(u'Newsletter title'),
        )

    body = RichTextField()

    date = models.DateField(
         _(u'Date'),
         help_text=_(u'Set date when this newsletter should be send') 
    )    

    class Meta:
        ordering = ['title',]

forms.py

from models import Newsletter, Mail
class NewsletterForm(forms.ModelForm):
    class Meta:
       model = Newsletter

视图:

from newsletter.models import Newsletter, Mail
from newsletter.forms  import NewsletterForm, MailForm

def newsletters_add(request):
    form = NewsletterForm()
    tpl  = "form_newsletter.html"

    return render_to_response(tpl, RequestContext(request, {
        'form': form,
    }))

成功输出所有表单

使用 {{ form }} 标记settings.py (项目的)

CKEDITOR_MEDIA_PREFIX  = "/media/ckeditor/"
CKEDITOR_UPLOAD_PATH   = "/www/vhosts/sender/media/newsletter/uploads/"
CKEDITOR_UPLOAD_PREFIX = "http://******/media/newsletter/uploads/"
CKEDITOR_RESTRICT_BY_USER = True

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Basic',
    },
}


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'django.contrib.admin',
    #'tagging',
    'debug_toolbar',
    'ckeditor',
    'mailer',
    'newsletter'

)

In Stack Overflow there's two questions about this editor, and nobody answers!!!

So I'm asking how to install this Django package to my project??
I've followed these steps already, have no errors, nothing, and still the form stays the same. Why??

Edit: heres model

from datetime import datetime

from django.db                import models
from django.utils.translation import ugettext_lazy as _, ugettext
from ckeditor.fields          import RichTextField

class Newsletter(models.Model):

    title = models.CharField(
        _(u'Title'),
        max_length=200,
        help_text=_(u'Newsletter title'),
        )

    body = RichTextField()

    date = models.DateField(
         _(u'Date'),
         help_text=_(u'Set date when this newsletter should be send') 
    )    

    class Meta:
        ordering = ['title',]

forms.py

from models import Newsletter, Mail
class NewsletterForm(forms.ModelForm):
    class Meta:
       model = Newsletter

view:

from newsletter.models import Newsletter, Mail
from newsletter.forms  import NewsletterForm, MailForm

def newsletters_add(request):
    form = NewsletterForm()
    tpl  = "form_newsletter.html"

    return render_to_response(tpl, RequestContext(request, {
        'form': form,
    }))

All form outputed succesfully with {{ form }} tag

settings.py (of the project)

CKEDITOR_MEDIA_PREFIX  = "/media/ckeditor/"
CKEDITOR_UPLOAD_PATH   = "/www/vhosts/sender/media/newsletter/uploads/"
CKEDITOR_UPLOAD_PREFIX = "http://******/media/newsletter/uploads/"
CKEDITOR_RESTRICT_BY_USER = True

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Basic',
    },
}


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'django.contrib.admin',
    #'tagging',
    'debug_toolbar',
    'ckeditor',
    'mailer',
    'newsletter'

)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹沉浮 2024-10-15 17:17:24

正确显示小部件所需的媒体应存储在表单的 media 对象中。您可以使用{{ form.media }}在模板中输出所需js的标签。管理员应该自动执行此操作,而在自定义视图中,您必须自己执行此操作...请参阅 表单媒体了解更多信息!

The media needed to display the widget correctly should be stored in the form's media object. You can output the tag for needed js in your template with {{ form.media }}. The admin should do this automatically, while in your custom views you have to do it yourself... See the django documentation on form media for more information!

走走停停 2024-10-15 17:17:24

好吧,抱歉我是个白痴。在文档中没有任何关于以某种方式手动包含 JS 的文字!所以只要包含它

<script src="http://****/media/ckeditor/ckeditor/ckeditor.js"></script>

开发人员是盲目的还是什么?

ok sorry i was an idiot. in documentation there's no words about including JS manually somehow! so just include it

<script src="http://****/media/ckeditor/ckeditor/ckeditor.js"></script>

Developers are blind in there or something?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文