python - Tinymce 未显示在 django 管理中

标签 python django tinymce admin wysiwyg

我已经在本地主机上安装了tinymce,一切正常。 然后我将其复制到 pythonanywhere 服务器,并且只有正常的内容字段,没有tinymce。 也许有人知道问题出在哪里?

我已经从本地主机复制了所有内容,一切正常。 现在他正在/static/中搜索tinmce的js,但是当我查看/static/时没有tinmce文件。 我的服务器上的安装有什么问题吗?

每一个要求也都得到满足。 也许有人可以告诉我我的错误在哪里?

错误日志显示:

2019-05-17 13:24:28,011: Not Found: /favicon.ico
2019-05-17 13:24:35,743: Not Found: /static/tiny_mce/tiny_mce.js
2019-05-17 13:24:35,878: Not Found: /static/django_tinymce/init_tinymce.js
2019-05-17 13:24:35,882: Not Found: /static/django_tinymce/jquery-1.9.1.min.js
2019-05-17 13:24:36,026: Not Found: /static/django_tinymce/init_tinymce.js

我的设置文件:

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 2.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

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__)))
TEMPLATES_DIR = os.path.join(BASE_DIR,'templates')


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0x!b#(1*cd73w$&azzc6p+essg7v=g80ls#z&xcx*mpemx&@9$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['dobricicuros.pythonanywhere.com']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'tinymce',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATES_DIR],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'de-de'

TIME_ZONE = 'Europe/Berlin'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')


###########################################################################
TINYMCE_DEFAULT_CONFIG = {
    'height': 360,
    'width': 1120,
    'cleanup_on_startup': True,
    'custom_undo_redo_levels': 20,
    'selector': 'textarea',
    'theme': 'modern',
    'plugins': '''
            textcolor save link image media preview codesample contextmenu
            table code lists fullscreen  insertdatetime  nonbreaking
            contextmenu directionality searchreplace wordcount visualblocks
            visualchars code fullscreen autolink lists  charmap print  hr
            anchor pagebreak
            ''',
    'toolbar1': '''
            fullscreen preview bold italic underline | fontselect,
            fontsizeselect  | forecolor backcolor | alignleft alignright |
            aligncenter alignjustify | indent outdent | bullist numlist table |
            | link image media | codesample |
            ''',
    'toolbar2': '''
            visualblocks visualchars |
            charmap hr pagebreak nonbreaking anchor |  code |
            ''',
    'contextmenu': 'formats | link image',
    'menubar': True,
    'statusbar': True,
    }

我的 URL 文件:

from . import views
from django.urls import path, re_path
from django.urls import include


urlpatterns = [
    path('', views.PostList.as_view(), name='home'),
    path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
    re_path(r'^tinymce/', include('tinymce.urls')),
] 

我的模型.py

from django.db import models
from django.contrib.auth.models import User
from tinymce.models import HTMLField


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

class Post(models.Model):
    title = models.CharField(max_length=200, unique=True)
    slug = models.SlugField(max_length=200, unique=True)
    author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
    updated_on = models.DateTimeField(auto_now= True)
    content = HTMLField('Content')
    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
<小时/>

我定义了 Static_ROOT 并运行collectstatic。 现在它向我显示这个错误:

2019-05-17 15:32:55,537: Not Found: /static/tiny_mce/themes/modern/editor_template.js
2019-05-17 15:32:55,544: Not Found: /static/tiny_mce/plugins/textcolor save link image media preview codesample contextmenu            table code lists fullscreen  insertdatetime  nonbreaking            contextmenu directionality searchreplace wordcount visualblocks            visualchars code fullscreen autolink lists  charmap print  hr            anchor pagebreak/editor_plugin.js

这是我的tinymce的settings.py配置部分:

TINYMCE_DEFAULT_CONFIG = {
    'height': 360,
    'width': 1120,
    'cleanup_on_startup': True,
    'custom_undo_redo_levels': 20,
    'selector': 'textarea',
    'theme': 'advanced',
    'plugins': '''
            textcolor save link image media preview codesample contextmenu
            table code lists fullscreen  insertdatetime  nonbreaking
            contextmenu directionality searchreplace wordcount visualblocks
            visualchars code fullscreen autolink lists  charmap print  hr
            anchor pagebreak
            ''',
    'toolbar1': '''
            fullscreen preview bold italic underline | fontselect,
            fontsizeselect  | forecolor backcolor | alignleft alignright |
            aligncenter alignjustify | indent outdent | bullist numlist table |
            | link image media | codesample |
            ''',
    'toolbar2': '''
            visualblocks visualchars |
            charmap hr pagebreak nonbreaking anchor |  code |
            ''',
    'contextmenu': 'formats | link image',
    'menubar': True,
    'statusbar': True,
    }

最佳答案

您是否运行了collectstatic 将这些文件从tinymce 放入静态文件夹?您是否设置了正确的 static file mapping在您的 PythonAnywhere Web 应用程序设置中?

关于python - Tinymce 未显示在 django 管理中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184923/

相关文章:

python - Django 重定向传递一个(或多个)对象作为参数

javascript - 如何跨多个 ASP.Net 站点共享 TinyMCE Javascript 源代码

python - 时间序列数据中的峰谷

python - Django 中的多字段外键

python - 无效的默认值 - Django 和 python

php - 将内容设置为多个 TinyMCE 文本区域?

javascript - 无需拖动即可添加图像 TinyMCE

python - python Scipy + sympy(?)中变量边界的双积分

python - 如何在 django 模板中设置页面范围的索引

python - Django/MySQL 中的间隙检测