2016-10-12 48 views
0

我讨厌提出类似案例中已经解决的那类问题,但自3天以来我就开始发疯了。无法在我的应用程序上设置django-ckeditor

我使用django 1.10 & jquery 3.1.1(已经在我的页面中加载另一个工具)。并尝试让django-ckeditor 5.1.1在我的项目上工作。我读过ckeditor_demo,它运行正常,因此软件包已正确安装。

我跟着git doc。并花了几个小时在Stack上。

通过的CKEditor我settings.py有关的设置:

from __future__ import absolute_import 
import tempfile 
import os 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.sites', 
    'blog', 
    'CreateYourLaws', 
    'captcha', 
    'registration', 
    'ckeditor', 
    'ckeditor_uploader', 
] 

# Plenty of others Settings for other tools... 

# Settings for ckeditors 
STATIC_URL = '/static/' 
MEDIA_URL = '/media/' 
STATIC_ROOT = os.path.join(tempfile.gettempdir(), 'ck_static') 
MEDIA_ROOT = os.path.join(tempfile.gettempdir(), 'ck_media') 

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

CKEDITOR_UPLOAD_PATH = "uploads/" 
CKEDITOR_IMAGE_BACKEND = "pillow" 

我也已经与设定的尝试:

CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' 

它也不管用。我最好删除它,因为我已经在我的模板中加载jquery 3.1.1。

我也已经运行了manage.py collectstatic命令(当然写了我的设置之后)。

urls.py

from django.conf.urls import url, include 
from . import views 
from django.conf import settings 
from django.conf.urls.static import static 
#... and few others 

urlpatterns = [ 
    url(r'^$', views.home, name='home'), 
    # ... many others 
    url(r'^article/(\d+)$', views.view_article, name='article'), 
    url(r'^ckeditor/', include('ckeditor_uploader.urls'),) 
] + static(
    settings.STATIC_URL, 
    document_root=settings.STATIC_ROOT 
) + static(
    settings.MEDIA_URL, 
    document_root=settings.MEDIA_ROOT 
) 

我的模型:

from django.db import models 
# Other imports... 
from ckeditor.fields import RichTextField 

class Reflection(models.Model): 
    title = models.CharField(max_length=150, blank=True, null=True) 
    # Some Attributes 

    class Meta: 
     abstract = True 
     #... 
class Proposition(Reflection): 
    text = RichTextField() 
    # Other attributes 

我的表格:

from django import forms 
# other imports... 
from CreateYourLaws.models import Proposition 
from ckeditor.widgets import CKEditorWidget 

class PropositionForm(forms.ModelForm): 
    class Meta: 
     model = Proposition 
     fields = ('title', 'text') 
     labels = {'title': ('Nommez votre proposition de loi'), 
        'text': ("votre proposition de loi")} 
     widgets = { 
      'text': CKEditorWidget() 
     } 

我的观点:

@login_required 
def view_article(request, id_article): 

    # A very good and interesting code... 

    if request.method == 'POST' and 'propform' in request.POST: 
     propform = PropositionForm(request.POST) 
     if propform.is_valid(): 
      proptitle = propform.cleaned_data['title'] 
      prop = propform.cleaned_data['text'] 
      prp = Proposition.objects.create(text=prop, 
              title=proptitle, 
              autor=User, 
              content_object=Article) 
      prp.save() 
    propform = PropositionForm() 
    # A bit of code... 
    return render(request, 
        'main.html', 
        locals()) 

我的模板:

{% block script %} 
    <script type="text/javascript" src="{% static 'js/jstree.min.js' %}"></script> 
    <script type="text/javascript" src="{% static 'js/jquery-ui.min.js' %}"></script> 
    <link rel="stylesheet" type="text/css" href="{% static 'js/jquery-ui.min.css' %}"></link> 
    <script type="text/javascript" src="{% static 'js/myJS_CYL.js' %}"></script> 
    <script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script> 
    <script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script> 
    <style type="text/css" media="screen"> 
     nav{display: block;}  
    </style> 
{% endblock %} 

{% block content %} 
     <section class="proposition"> 
      <form action="{% url 'article' Article.id %}" method="post" class="propform"> 
       {% csrf_token %} 
       {{ propform.as_p }} 
       <button type="submit" class="butprop" name="propform">Poster votre proposition </button> 
      </form> 
     </section> 
{% endblock %} 

我已经与添加{{ propform.media }}也试过它不工作,要么并根据文档,如果在头部添加脚本是没用的。

我的页面正常加载,一切正常,在终端没有错误,但代替我的CKEditorWidget,我仍然有我简单的TextArea。我做错了什么和/或忘记了?

红利问题:我不需要在我的CKeditorwidget中上传任何东西。我可以删除'ckeditor_uploader'应用程序的哪些设置和URL? MEDIA_URL,MEDIA_ROOT,CKEDITOR_UPLOAD_PATH,CKEDITOR_IMAGE_BACKEND? 'ckeditor_uploader.urls'?

感谢您的时间和你的回答

回答

0

好的抱歉,这篇文章。它正在工作,但不在右侧文本区域:我有一个页面,其中有几个隐藏表格,其中有不同的文本区域,这取决于用户的操作。我想要一个特定的工作与Ckeditorwidget。 对不起,所以,我不是一个专业的,只是一个业余爱好者。

0

好的我找到了主要问题:所有文本区mus在页面上有不同的名称。我的页面中有4种不同的表单,每种表单中都有一个名为“文本”的字段,因此只有第一个CKeditor正确加载。

相关问题