简体   繁体   English

Django-ckeditor 404错误

[英]Django-ckeditor 404 errors

I'm receiving several 404-errors when using django-ckeditor.我在使用 django-ckeditor 时收到几个 404 错误。

This is what my static folder looks like这是我的 static 文件夹的样子

The first is on the ckeditor.js file, which is located at static/boot/ckeditor/ckeditor and the error I receive is as follows: "GET /static/ckeditor.js HTTP/1.1" 404 1657第一个是位于static/boot/ckeditor/ckeditorckeditor.js文件,我收到的错误如下: "GET /static/ckeditor.js HTTP/1.1" 404 1657

Following, I receive a few errors on other documents that are actually in the folders where I get an error:接下来,我收到一些关于其他文档的错误,这些错误实际上位于我收到错误的文件夹中:

"GET .../AGAPE/static/boot/ckeditor/ckeditor/config.js?t=JB9C HTTP/1.1" 404 2494

"GET .../AGAPE/static/boot/ckeditor/ckeditor/skins/moono-lisa/editor.css?t=JB9C HTTP/1.1" 404 2548

"GET .../AGAPE/static/boot/ckeditor/ckeditor/lang/nl.js?t=JB9C HTTP/1.1" 404 2497

For the last three, I imagine that the error is caused by the characters that are added at the end of the file name, eg ?t=JB9C , but I don't get why these characters are added.对于最后三个,我想错误是由在文件名末尾添加的字符引起的,例如?t=JB9C ,但我不明白为什么要添加这些字符。

Additionally, my settings.py file:此外,我的settings.py文件:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/boot/')
STATIC_FILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'boot'),]

MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR), 'media')
MEDIA_URL="/media/"

CKEDITOR_BASEPATH = os.path.join(os.path.dirname(STATIC_ROOT), 'ckeditor/ckeditor/')

CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDIT_IMAGE_BACKEND = 'pillow'

CKEDITOR_CONFIGS = {
   'default': {
        'toolbar':[ ['CodeSnippet', ], ],
        'height': 400,
        'width': 900,
        'removePlugins': 'stylesheetparser',
        'extraPlugins': 'codesnippet',
   },
}

And the relevant models.py file (in the relevant app):以及相关的models.py文件(在相关的应用程序中):

from django.db import models
from django.contrib.auth.models import User
from ckeditor_uploader.fields import RichTextUploadingField
from ckeditor.fields import RichTextField

STATUS = (
    (0,"Draft"),
    (1,"Publish")
)

class Post(models.Model):
    title = models.CharField(max_length=200, unique=True)
    cover = models.ImageField(upload_to='images/')
    author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
    slug = models.SlugField(null=False, unique=True)
    def get_absolute_url(self):
        return reverse('post_detail', kwargs={'slug': self.slug})
    updated_on = models.DateTimeField(auto_now= True)
    content = RichTextUploadingField(blank=True)
    created_on = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(choices=STATUS, default=0)

    class Meta:
        ordering = ['-created_on']

    def __str__(self):
        return self.title

The admin.py file (in the relevant app): admin.py文件(在相关应用程序中):

from django.contrib import admin
from .models import Post 

class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'status','created_on')
    list_filter = ("status",)
    search_fields = ['title', 'content']
    prepopulated_fields = {'slug': ('title',)}
    class Media:
        js = ('ckeditor.js',)
        # do not write '/static/ckeditor.js' as Django automatically looks 
        # in the static folder

admin.site.register(Post, PostAdmin)

The urls.py file (global): urls.py文件(全局):

from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include
from django.urls import include, path
from django.conf.urls.static import static
from AGAPE import views
from articles import views
from django.views.generic.base import TemplateView
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import ugettext_lazy as _


urlpatterns = i18n_patterns(
    url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
    url(r'^i18n/', include('django.conf.urls.i18n')),
    path('i8n/', include('django_translation_flags.urls')),
    url(r'^home', TemplateView.as_view(template_name='home.html'), name='home'),
    url(r'^overagape', TemplateView.as_view(template_name='overagape.html'),name='over_agape'),
    url(r'^QUIZ/', include('QUIZ.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^nested_admin/', include('nested_admin.urls')),
    url(r'^aspecteen', TemplateView.as_view(template_name='aspecteen.html'), name='aspecteen'),
    url(r'^aspecttwee', TemplateView.as_view(template_name='aspecttwee.html'), name='aspecttwee'),
    url(r'^aspectdrie',TemplateView.as_view(template_name='aspectdrie.html'),name='aspectdrie'),
    url(r'^aspectvier',TemplateView.as_view(template_name='aspectvier.html'),name='aspectvier'),
    url(r'^aspectvijf',TemplateView.as_view(template_name='aspectvijf.html'),name='aspectvijf'),
    url(r'^articles/', include('articles.urls')),
    url(r'^ckeditor/', include ('ckeditor_uploader.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I had the same problem and the problem was about the script I call ckeditor in the template.我有同样的问题,问题是关于我在模板中调用 ckeditor 的脚本。

Before it was like this;以前是这样;

<script type="text/javascript" src="{% static ' ckeditor/ckeditor-init.js' %}"></script>
<script type="text/javascript" src="{% static ' ckeditor/ckeditor/ckeditor.js' %}"></script>

and the space between apostrophe symbol and ckeditor path caused django to call it as;撇号和 ckeditor 路径之间的空格导致 django 将其称为;

"GET /static/%20ckeditor/ckeditor-init.js HTTP/1.1" 404 1706    
"GET /static/%20ckeditor/ckeditor/ckeditor.js HTTP/1.1" 404 1718

problem has gone after deleting the space.删除空格后问题消失了。 Could be helpful in some cases.在某些情况下可能会有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM