我正在构建一个 django 应用程序,它需要 javascript 文件来实现某些 ajaxy 位。我想打包这个应用程序,以便可以通过 easy_install 或 pip 尽可能轻松地安装它。
但我不确定静态媒体应该放在哪里,特别是 javascript 文件。在我的机器上,我的静态媒体位于外部目录中,不是由 django 提供的。我的模板中的所有内部引用都指向 MEDIA_URL。
对于可重用 django 应用程序的打包/包含/附加静态媒体的位置是否有标准?有没有一种方法可以打包应用程序,以便其他人可以直接使用它,而无需移动所有 javascript/css 文件,或者有什么方法可以在安装过程中实现自动化?
我正在使用 django 1.2——尚未将服务器升级到 1.3。
I'm building a django app that requires a javascript file for some ajaxy bits. I would like to package this app so that it can be installed by via easy_install or pip with as little fuss as possible.
But I'm not sure what where to put the static media, particularly the javascript file. On my machine, I have the static media in an external directory, not served by django. All the internal references in my template point to MEDIA_URL.
Is there a standard for where to package/include/attach static media for reusable django apps? Is there a way to package the app so that others can just use it without messing with moving all the javascript/css files, or some way to automate that during the install process?
I'm using django 1.2 -- haven't upgraded the server to 1.3.
发布评论
评论(1)
我认为
staticfiles
应用程序 正是你正在寻找什么,不幸的是它是 Django 1.3 中的新内容。你能升级吗?来自文档:
编辑:根据Wogan的评论,如果您不想升级到1.3,那么您可以使用静态文件独立应用。这就是 Django 内置的 staticfiles 应用程序最初的来源。
I think the
staticfiles
app is exactly what you're looking for, unfortunately it's new in Django 1.3. Are you able to upgrade?From the docs:
EDIT: As per Wogan's comment, if you don't want to upgrade to 1.3 then you can use the Staticfiles standalone app. It's what Django's built in staticfiles app was originally derived from.