Django Tinymce js 未加载

发布于 2024-10-18 10:11:22 字数 1079 浏览 1 评论 0原文

大家好 我正在尝试将tinymce集成到django管理页面中。 我已经安装了 django-tinymce 模块(http://code.google.com/p/django-tinymce/) 我按照说明操作,所以这些是我的文件:

settings.py

INSTALLED_APPS = (
    ...
    'tinymce',
)


TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,paste,searchreplace",
    'theme': "advanced",
}
TINYMCE_SPELLCHECKER = False
TINYMCE_COMPRESSOR = False

url.py

urlpatterns = patterns('',
    # Example:
    # (r'^uboPy/', include('uboPy.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
        (r'^admin/', include(admin.site.urls)),
        (r'^tinymce/', include('tinymce.urls')),
)

我将tinymce的js放在根目录中名为media/js 在模型中,我有这一行: text = tinymce_models.HTMLField()

当我运行服务器时,我没有收到错误,但是当我进入模型的管理区域时,tinymce 未加载。使用 firebug,我看到tinymce 库给出了 404 错误,但路径是正确的..我的 url.py 中有一些问题?

谢谢你的帮助

hi all
Im tryng to integrate a tinymce in a django admin page.
I've installed the django-tinymce module (http://code.google.com/p/django-tinymce/)
I followed the instructions so these are my files:

settings.py

INSTALLED_APPS = (
    ...
    'tinymce',
)


TINYMCE_DEFAULT_CONFIG = {
    'plugins': "table,paste,searchreplace",
    'theme': "advanced",
}
TINYMCE_SPELLCHECKER = False
TINYMCE_COMPRESSOR = False

url.py

urlpatterns = patterns('',
    # Example:
    # (r'^uboPy/', include('uboPy.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
        (r'^admin/', include(admin.site.urls)),
        (r'^tinymce/', include('tinymce.urls')),
)

i have the tinymce's js in a folder in the root called media/js
In the model i've this line: text = tinymce_models.HTMLField()

when i run the server i don't get error but when i go in the admin area of my model the tinymce is not loaded. With firebug i see that the tinymce library give a 404 error but the path is correct.. i have some problem in my url.py?

thanks for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失退 2024-10-25 10:11:22

您是否只是在项目根目录中放置一个名为 media/js 的文件夹?它实际上需要以某种方式从某处的 url 提供服务。

JavaScript 文件是通过浏览器加载的,因此它需要能够通过所有其他媒体所在的互联网进行访问。这部分与 django 无关,因此您不应该期望出现错误或 URL 问题。

解决该部分后,请通过 TINYMCE_JS_URL 设置参数指定可访问该文件的 URL。

例如,在我的设置中,js 是..

TINYMCE_JS_URL = '/media/js/tiny_mce/tiny_mce.js'

有了 Firebug,我发现tinymce
库给出 404 错误,但路径
是正确的..

您是说您可以访问此 URL 路径并加载 JS 文件吗?我想说的是:如果是404,路径如何正确?

Are you just putting a folder in your project root called media/js? It actually needs to be served somehow from a url somewhere.

The JavaScript file is loaded via your browser, so it needs to be accessible to the internet where all of your other media lives. This part has nothing to do with django, so you shouldn't expect errors or URL issues.

Once you've solved that part, specify the URL where the file can be accessed via the TINYMCE_JS_URL settings parameter.

For example, on my setup, the js is..

TINYMCE_JS_URL = '/media/js/tiny_mce/tiny_mce.js'

With firebug i see that the tinymce
library give a 404 error but the path
is correct..

Are you saying you can visit this URL path and the JS file loads? What I'm saying is: how is the path correct if it's a 404?

維他命╮ 2024-10-25 10:11:22

我发现 django-tinymce 文档已经过时,即部分错误。

我发现不同版本的tinymce和django-tinymce包不兼容。

我解决了这个问题,在我的project/settings.py 中添加了一些变量并更改了tinymce 目录和文件名。

django-tinymce urls.py 中有一些硬编码路径,假设目录被命名为“tiny_mce”,而实际上它们被命名为“tinymce”,因此我必须重命名它们,或者更改 django-tinymce urls.py。

# project setting.py
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_JS_DIR = os.path.join(STATIC_DIR, "js")
TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
#TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
#TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")

I found out the django-tinymce documentation is outdated, i.e. partially wrong.

What I discovered is that different versions of tinymce and django-tinymce packages are not compatible.

I solved it adding some variables to my project/settings.py and altering the tinymce directory and file names.

django-tinymce urls.py had some hardcoded paths in it which assumed the directories were named "tiny_mce" when in reality they were named "tinymce", hcen I had to rename them, or change the django-tinymce urls.py.

# project setting.py
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_JS_DIR = os.path.join(STATIC_DIR, "js")
TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
#TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
#TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文