Django-tinymce和django-filebrowser,图片上传错误查找上传文件夹(MEDIA_ROOT + DIRECTORY)

时间:2021-07-17 07:22:34

So I'm trying to get filebrowser working with tinymce in django. Evrything goes fine with tinymce, nice fancy text editor. When I try to open the file browser i get ImproperlyConfigured at /admin/filebrowser/browse/ Error finding Upload-Folder (MEDIA_ROOT + DIRECTORY). Maybe it does not exist?I don't get any errors in the console from that and so far as i can tell it should be looking for /media/filebrowser/ which definitely exist

所以我试图让文件浏览器在django中使用tinymce。 Evrything与tinymce,漂亮的花哨文本编辑器相得益彰。当我尝试打开文件浏览器时,我在/ admin / filebrowser / browse /错误查找上传文件夹(MEDIA_ROOT + DIRECTORY)时得到ImproperlyConfigured。也许它不存在?我没有在控制台中得到任何错误,据我所知它应该寻找/ media / filebrowser /肯定存在

python manage.py test filebrowser give me this:

FAIL: test_directory (filebrowser.tests.settings.SettingsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/nada/costumeshoppe/filebrowser/tests/settings.py", line 29, in test_directory
    self.assertEqual(os.path.exists(os.path.join(MEDIA_ROOT,DIRECTORY)), 1)

AssertionError: False != 1

AssertionError:False!= 1

my settings:

STATIC_ROOT = ROOT_PATH +'/public/static/'
STATIC_URL = '/static/'
MEDIA_ROOT = ROOT_PATH + '/public/media/'
MEDIA_URL = '/media/'
TINYMCE_JS_ROOT = '/static/tiny_mce/'
TINYMCE_JS_URL = os.path.join(STATIC_URL, "tiny_mce/tiny_mce_src.js")
TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,spellchecker,paste,searchreplace,styles",
    'theme': "advanced",
}

my urls:

if settings.DEBUG:
        urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve',  {'document_root': settings.MEDIA_ROOT,})
   )

urlpatterns += staticfiles_urlpatterns()

I'm running in debug mode, don't know if that's the problem, do have a weird issue where i can use the static url to load static files but they have to be in the media directory, though the filebrowser static files are in my static file location which fixed some installation problems, but putting those files in media location as well didn't change anything. Any ideas what is needed to do to get this to work?

我在调试模式下运行,不知道是不是问题,确实有一个奇怪的问题,我可以使用静态URL加载静态文件,但它们必须在媒体目录中,尽管文件浏览器静态文件在我的静态文件位置修复了一些安装问题,但将这些文件放在媒体位置也没有改变任何东西。有什么需要做才能让它发挥作用?

4 个解决方案

#1


12  

The Default FILEBROWSER_DIRECTORY is "uploads" so you should check if '/media/uploads' exists

默认FILEBROWSER_DIRECTORY是“上传”,因此您应该检查'/ media / uploads'是否存在

#2


3  

DIRECTORY is set in filebrowser.settings by default to uploads/ does this folder exist inside your media root?

DIRECTORY默认设置在filebrowser.settings中上传/你的媒体根目录中是否存在此文件夹?

This default can be changed in your settings.py with FILEBROWSER_DIRECTORY

可以使用FILEBROWSER_DIRECTORY在settings.py中更改此默认值

#3


0  

Yes, you should add a new directory names "uploads".

是的,您应该添加新目录名称“uploads”。

In it's official DOC, you can find the anwser.

在它的官方DOC中,你可以找到anwser。

https://django-filebrowser.readthedocs.org/en/3.5.2/settings.html#directory-relative-to-media-root

DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/')

#4


0  

If anyone have the same issue, please read this post. It worked for me.

如果有人有同样的问题,请阅读这篇文章。它对我有用。

Excerpting the content for posterity:

摘录后人的内容:

If you want to use tinymce widget to edit zinnia blog posts you may also want to use filebrowser to insert / edit images using your media django media folder. It does not work out of the box.

如果您想使用tinymce小部件来编辑百日草博客文章,您可能还想使用filebrowser使用您的media django媒体文件夹插入/编辑图像。它不是开箱即用的。

  • install zinnia
  • install filebrowser
  • install django-tinymce

And create your own file admin/zinnia/entry/tinymce_textareas.js with content:

并创建自己的文件admin / zinnia / entry / tinymce_textareas.js,内容如下:

tinyMCE.init({
    file_browser_callback: "djangoFileBrowser", // <---- this makes filebrowser work!
    mode: "exact",
    elements: "id_content",
    theme: "advanced",
    skin_variant : "silver",
    height: "250",
    width: "800",
    relative_urls: false,
    language: "en",
    directionality: "ltr",
    spellchecker_languages : "Arabic=ar,Azerbaijani=az,Bulgarian=bg,Bengali=bn,Bosnian=bs,Catalan=ca,Czech=cs,Welsh=cy,Danish=da,German=de,Greek=el,+English / British English=en,Esperanto=eo,Spanish / Argentinian Spanish / Mexican Spanish / Nicaraguan Spanish=es,Estonian=et,Basque=eu,Persian=fa,Finnish=fi,French=fr,Frisian=fy,Irish=ga,Galician=gl,Hebrew=he,Hindi=hi,Croatian=hr,Hungarian=hu,Indonesian=id,Icelandic=is,Italian=it,Japanese=ja,Georgian=ka,Kazakh=kk,Khmer=km,Kannada=kn,Korean=ko,Lithuanian=lt,Latvian=lv,Macedonian=mk,Malayalam=ml,*n=mn,Norwegian Bokmal=nb,Nepali=ne,Dutch=nl,Norwegian Nynorsk=nn,Punjabi=pa,Polish=pl,Portuguese / Brazilian Portuguese=pt,Romanian=ro,Russian=ru,Slovak=sk,Slovenian=sl,Albanian=sq,Serbian / Serbian Latin=sr,Swedish=sv,Swahili=sw,Tamil=ta,Telugu=te,Thai=th,Turkish=tr,Tatar=tt,Ukrainian=uk,Urdu=ur,Vietnamese=vi,Simplified Chinese / Traditional Chinese=zh",
    spellchecker_rpc_url : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    plugins: "contextmenu,directionality,fullscreen,paste,preview,searchreplace,spellchecker,visualchars,wordcount",
    paste_auto_cleanup_on_paste : true,
    theme_advanced_buttons1 : "formatselect,fontsizeselect,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,visualchars,visualaid,cleanup,code,preview,fullscreen",
    theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,removeformat,|,justifyleft,justifycenter,justifyright,justifyfull,|,sub,sup,|,bullist,numlist,|,outdent,indent,|,link,unlink,anchor,image,blockquote,hr,charmap,",
    theme_advanced_buttons3 : ""
});

#1


12  

The Default FILEBROWSER_DIRECTORY is "uploads" so you should check if '/media/uploads' exists

默认FILEBROWSER_DIRECTORY是“上传”,因此您应该检查'/ media / uploads'是否存在

#2


3  

DIRECTORY is set in filebrowser.settings by default to uploads/ does this folder exist inside your media root?

DIRECTORY默认设置在filebrowser.settings中上传/你的媒体根目录中是否存在此文件夹?

This default can be changed in your settings.py with FILEBROWSER_DIRECTORY

可以使用FILEBROWSER_DIRECTORY在settings.py中更改此默认值

#3


0  

Yes, you should add a new directory names "uploads".

是的,您应该添加新目录名称“uploads”。

In it's official DOC, you can find the anwser.

在它的官方DOC中,你可以找到anwser。

https://django-filebrowser.readthedocs.org/en/3.5.2/settings.html#directory-relative-to-media-root

DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/')

#4


0  

If anyone have the same issue, please read this post. It worked for me.

如果有人有同样的问题,请阅读这篇文章。它对我有用。

Excerpting the content for posterity:

摘录后人的内容:

If you want to use tinymce widget to edit zinnia blog posts you may also want to use filebrowser to insert / edit images using your media django media folder. It does not work out of the box.

如果您想使用tinymce小部件来编辑百日草博客文章,您可能还想使用filebrowser使用您的media django媒体文件夹插入/编辑图像。它不是开箱即用的。

  • install zinnia
  • install filebrowser
  • install django-tinymce

And create your own file admin/zinnia/entry/tinymce_textareas.js with content:

并创建自己的文件admin / zinnia / entry / tinymce_textareas.js,内容如下:

tinyMCE.init({
    file_browser_callback: "djangoFileBrowser", // <---- this makes filebrowser work!
    mode: "exact",
    elements: "id_content",
    theme: "advanced",
    skin_variant : "silver",
    height: "250",
    width: "800",
    relative_urls: false,
    language: "en",
    directionality: "ltr",
    spellchecker_languages : "Arabic=ar,Azerbaijani=az,Bulgarian=bg,Bengali=bn,Bosnian=bs,Catalan=ca,Czech=cs,Welsh=cy,Danish=da,German=de,Greek=el,+English / British English=en,Esperanto=eo,Spanish / Argentinian Spanish / Mexican Spanish / Nicaraguan Spanish=es,Estonian=et,Basque=eu,Persian=fa,Finnish=fi,French=fr,Frisian=fy,Irish=ga,Galician=gl,Hebrew=he,Hindi=hi,Croatian=hr,Hungarian=hu,Indonesian=id,Icelandic=is,Italian=it,Japanese=ja,Georgian=ka,Kazakh=kk,Khmer=km,Kannada=kn,Korean=ko,Lithuanian=lt,Latvian=lv,Macedonian=mk,Malayalam=ml,*n=mn,Norwegian Bokmal=nb,Nepali=ne,Dutch=nl,Norwegian Nynorsk=nn,Punjabi=pa,Polish=pl,Portuguese / Brazilian Portuguese=pt,Romanian=ro,Russian=ru,Slovak=sk,Slovenian=sl,Albanian=sq,Serbian / Serbian Latin=sr,Swedish=sv,Swahili=sw,Tamil=ta,Telugu=te,Thai=th,Turkish=tr,Tatar=tt,Ukrainian=uk,Urdu=ur,Vietnamese=vi,Simplified Chinese / Traditional Chinese=zh",
    spellchecker_rpc_url : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    plugins: "contextmenu,directionality,fullscreen,paste,preview,searchreplace,spellchecker,visualchars,wordcount",
    paste_auto_cleanup_on_paste : true,
    theme_advanced_buttons1 : "formatselect,fontsizeselect,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,search,replace,|,visualchars,visualaid,cleanup,code,preview,fullscreen",
    theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,removeformat,|,justifyleft,justifycenter,justifyright,justifyfull,|,sub,sup,|,bullist,numlist,|,outdent,indent,|,link,unlink,anchor,image,blockquote,hr,charmap,",
    theme_advanced_buttons3 : ""
});