我按照here中的说明将TinyMCE安装到django Admin后端。
但它不起作用。检查控制台日志时,我看到了:
http://127.0.0.1:8000/media/js/tiny_mce/tiny_mce.js Failed to load
我需要手动添加js文件吗? github中的指令没有提到这一点。
更新
确实要使其工作,必须将tiny_mce移动到静态文件夹。 对于任何有类似问题的人来说,这是我的解决方案。
settins.py
STATIC_URL = '/static/'
STATIC_ROOT = ''
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
#this is for localhost development, if you are in production enviroment, you will need to remove the STATICFILES_DIRS and define your STATIC_ROOT
TINYMCE_DEFAULT_CONFIG = {
'plugins' : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,pagebreak",
'theme': "advanced",
'theme_advanced_buttons1' : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,fullscreen,code,|,preview,image,media",
'theme_advanced_buttons2' : "table,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,forecolor,backcolor, emotions,|,pagebreak,paste",
'theme_advanced_buttons3 ': "",
'theme_advanced_toolbar_location' : "top",
'theme_advanced_toolbar_align' : "left",
'width': '700',
'height': '400'
}
admin.py
class AdminPost(admin.ModelAdmin):
class Media:
js = ('/static/js/tiny_mce/tiny_mce.js',)
答案 0 :(得分:1)
此问题有两个可能的原因。
1。)您拥有所需的文件,但位于与脚本标记中指定的位置不同的位置。将脚本标记中的网址更改为有效位置,它将起作用
2。)您没有所需的文件。下载源文件并将它们放在指定的位置,它将起作用。
答案 1 :(得分:1)
Django TinyMCE将媒体网址作为默认值,您可以在文档中看到:
TINYMCE_JS_URL (default: settings.MEDIA_URL + 'js/tiny_mce/tiny_mce.js')
TINYMCE_JS_ROOT (default: settings.MEDIA_ROOT + 'js/tiny_mce')
如果您更喜欢使用静态文件夹中的静态文件,则必须将这些值设置为正确的路径。我会说:
TINYMCE_JS_URL = settings.STATIC_URL + 'js/tiny_mce/tiny_mce.js'
TINYMCE_JS_ROOT = settings.STATIC_ROOT + 'js/tiny_mce'
现在您必须确保在STATICFILES_FINDERS设置中使用“django.contrib.staticfiles.finders.AppDirectoriesFinder”,以便不必在开发环境中复制文件,并使用collectstatic收集。 / p>
答案 2 :(得分:0)
您应该尝试:-
首先卸载tinymce
pip卸载django-tinymce4
然后重新安装tinymce
对我有用