简体   繁体   English

django-tinymce编辑器中的弹出窗口显示404错误

[英]Pop-ups in django-tinymce editor showing 404 error

What is wrong: 怎么了:

I have installed django-tinymce to work with text fields in the admin section of my site. 我已经安装了django-tinymce,可以在我网站的admin部分中使用文本字段。 The editor works good, though not as expected, because whenever I try to insert an image, link, symbol etc. - that is, whenever a pop-up is ensued - editor opens a 404 Not found window instead of actual widget form. 该编辑器运行良好,尽管效果不理想,因为每当我尝试插入图像,链接,符号等时(即,每当出现弹出窗口时),编辑器都会打开404 Not found窗口,而不是实际的窗口小部件形式。

What I have tried: 我试过的

I 've tried adding 我尝试添加

document.domain = 'my_site.com';

to tiny_mce_popup.js . tiny_mce_popup.js Nothing changed. 没有改变。

Interestingly enough, the *.htm files, which are supposed to open in pop-up windows, are stored in the directory {{ MEDIA_URL }}js/tiny_mce/themes/advanced/ (as I've mentioned, server doesn't open them). 有趣的是,应该在弹出窗口中打开的* .htm文件存储在目录{{MEDIA_URL}} js / tiny_mce / themes / advanced /中(如前所述,服务器无法打开他们)。 But if I try and open in browser other files from that very same directory (eg {{ MEDIA_URL }}js/tiny_mce/themes/advanced/editor_template.js or {{ MEDIA_URL }}js/tiny_mce/themes/advanced/img/flash.gif), everything works - the files are displayed without any error. 但是,如果我尝试在浏览器中打开同一目录中的其他文件(例如{{MEDIA_URL}} js / tiny_mce / themes / advanced / editor_template.js或{{MEDIA_URL}} js / tiny_mce / themes / advanced / img / flash .gif),一切正常-文件显示无任何错误。

In addition, on local server everything works just fine - the problem is encountered only after deployment. 另外,在本地服务器上,一切都可以正常工作-仅在部署后才遇到问题。

Code that might help identifying the problem: 可能有助于识别问题的代码:

Project's urls.py : 项目的urls.py

urlpatterns = patterns('',
    #...
    url(r'^tinymce/', include('tinymce.urls')),
    #...
)

TinyMCE's urls.py : TinyMCE的urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('tinymce.views',
    url(r'^js/textareas/(?P<name>.+)/$', 'textareas_js', name='tinymce-js'),
    url(r'^js/textareas/(?P<name>.+)/(?P<lang>.*)$', 'textareas_js', name='tinymce-js-lang'),
    url(r'^spellchecker/$', 'spell_check'),
    url(r'^flatpages_link_list/$', 'flatpages_link_list'),
    url(r'^compressor/$', 'compressor', name='tinymce-compressor'),
    url(r'^filebrowser/$', 'filebrowser', name='tinymce-filebrowser'),
    url(r'^preview/(?P<name>.+)/$', 'preview', name='tinymce-preview'),
)

TinyMCE's settings.py : TinyMCE的settings.py

import os
from django.conf import settings

DEFAULT_CONFIG = getattr(settings, 'TINYMCE_DEFAULT_CONFIG',
        {'theme': "advanced", 'relative_urls': False})

USE_SPELLCHECKER = getattr(settings, 'TINYMCE_SPELLCHECKER', False)

USE_COMPRESSOR = getattr(settings, 'TINYMCE_COMPRESSOR', False)

USE_FILEBROWSER = getattr(settings, 'TINYMCE_FILEBROWSER',
        'filebrowser' in settings.INSTALLED_APPS)

JS_URL = getattr(settings, 'TINYMCE_JS_URL',
        '%sjs/tiny_mce/tiny_mce.js' % settings.MEDIA_URL)

JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT',
        os.path.join(settings.MEDIA_ROOT, 'js/tiny_mce'))


JS_BASE_URL = JS_URL[:JS_URL.rfind('/')]

So how do I make django-tinymce's pop-ups work? 那么,如何使django-tinymce的弹出窗口起作用? Thanks in advance for your help! 在此先感谢您的帮助!

EDIT: Solution found. 编辑:找到解决方案。 Turns out my hosting provider didn't include htm(l) in allowed static files extensions list. 原来我的托管服务提供商未在允许的静态文件扩展名列表中包含htm(l) Now everything's working. 现在一切正常。

The fact that it is working under the development server, but not live, leads me to think that you haven't set up the media root properly in your apache conf. 它可以在开发服务器下运行,但不能运行,这一事实使我认为您尚未在apache conf中正确设置媒体根目录。 The development server automatically serves your media and static files but for your live deployment you need to add the media and static aliases with the relevant path. 开发服务器会自动为您的媒体和静态文件提供服务,但是对于您的实时部署,您需要使用相关路径添加媒体和静态别名。

vhost.conf: vhost.conf:

<VirtualHost *:80>
    # Your setup for your main site url, then add the below to allow access
    # to the media and static roots

    Alias /media/ "/path/to/myproject/media/"
    <Directory "/path/to/myproject/media/">
        Order deny,allow
        Allow from all
    </Directory>

    Alias /static/ "/path/to/myproject/static/"
    <Directory "/path/to/myproject/static/">
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

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

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