2016-10-12 3 views
0

私は同じようなケースですでに解決されている質問をしたくないのですが、3日からそれに怒っています。私のアプリでdjango-ckeditorを設定できません

私は、django 1.10 & Jquery 3.1.1(別のツールのために私のページに読み込まれています)を使用します。私のプロジェクトでdjango-ckeditor 5.1.1を作ろうとします。私はckeditor_demoを実行しているので、パッケージが正しくインストールされるように動作しました。

私はgit docに従っています。 Stackに数時間を費やしました。私settings.pyにCKEditorバージョンに関係

設定:

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に何もアップロードする必要はありません。どの設定とURLを 'ckeditor_uploader'アプリから削除できますか? MEDIA_URL、MEDIA_ROOT、CKEDITOR_UPLOAD_PATH、CKEDITOR_IMAGE_BACKEND? 'ckeditor_uploader.urls'?

お返事ありがとうございます

答えて

0

大変申し訳ありません。それは動作していますが、正しくはありません。テキスト領域:私は、ユーザーの操作に応じて表示される異なるテキスト領域を持ついくつかの隠れフォームを持つページを持っています。そして、私はCkeditorwidgetを使って具体的な作業をしたいと思っています。 申し訳ありませんが、私は専門家ではなく、ただのアマチュアです。

0

私は主な問題を発見しました:すべてのテキスト領域は、ページ上の異なる名前を持っています。私は4つの異なるフォームを各フォームに「テキスト」というフィールドがあるので、最初のものだけがCKeditorが正しくロードされていました。

関連する問題