姜戈;我如何从自定义“皮肤”内部提供模板/图像/css/js?目录?
我正在尝试制作一个可换肤的 Django 项目。
我遇到的问题是弄清楚如何从皮肤目录中而不是从媒体目录中提供文件,以便所有皮肤的图像/css/js 文件都可以驻留在皮肤的文件夹中)。
用户应该能够选择皮肤名称,最好仅通过更改“设置”中的 SKIN_NAME 变量(也许稍后是 .ini 文件)。所有模板/css/图像都将从该目录加载。
我想能够查看原始模板会很糟糕,所以也许它应该是皮肤文件夹内的“media”目录,其中包含子文件夹“css”,“js”和“images”,并且它将由那里。
尽管我有一些 Python 经验,但我对 Django 框架还很陌生,因此任何有关如何完成此操作的意见将不胜感激。
I'm trying to make a skinnable Django project.
What i'm having problems with is figuring out how i can serve file(s) from within the skin directory, and not from the media dir, so that all the skin's images/css/js files can reside in the skin's folder(s).
A user should be able to choose a skin name , preferably by only altering a SKIN_NAME variable in 'settings' (and maybe later an .ini file). And all templates/css/images would get loaded from this directory.
I imagine being able to view the raw templates would be bad, so perhaps it should be a 'media' directory inside the skin folder, with the subfolders 'css', 'js' and 'images' inside, and it would be served from there.
I'm pretty new to the Django framework even though i have some Python experience, so any input on how this is/can be done would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该将静态文件保存在
static
文件夹中,并且仅使用media
来上传内容。然后,在您的
static
文件夹中,您可以为每个皮肤创建一个文件夹,其中包含所需的所有 CSS、图像和 JS。只需从您的皮肤模板导入以 {{ STATIC_URL }} 和您的皮肤名称为前缀的文件即可。
如果您的皮肤不需要单独的模板,您甚至可以这样做:
First thing, you should rather keep your static files in a
static
folder and only usemedia
for uploaded content.Then within your
static
folder you could have a folder for each of your skin containing all the CSS, images and JS needed.From your skin template just import the files prefixed by both {{ STATIC_URL }} and your skin name.
If your skins do not need a separate template you could even do :
当用户选择“皮肤”名称时,请在设置文件中更改 MEDIA_ROOT。
将来,如果这更改为可在管理中更改的可配置设置变量,您可能可以使用更改 MEDIA_ROOT 值的中间件获得相同的结果。
When the user selects a "skin" name, have that change MEDIA_ROOT in your settings file.
Down the road, if this changes to a configurable settings variable that would be changed in the Admin, you could probably achieve the same result with a middleware that changes the value of MEDIA_ROOT.