How do I install django-ckeditor?

大城市里の小女人 提交于 2019-12-06 05:23:31

问题


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'

)

回答1:


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!




回答2:


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?



来源:https://stackoverflow.com/questions/4494912/how-do-i-install-django-ckeditor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!