Django - javascript和css文件中的模板标记 [英] Django - Template tags in javascript and css files

查看:119
本文介绍了Django - javascript和css文件中的模板标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将模板标签添加到javascript和css文件中?我会使用它的任何东西,从传递url到媒体url链接(图像路径等)到基于用户权限的条件JavaScript。

Is there any way to add template tags into javascript and css files? I would use it for anything from passing in urls to media url links (image paths, etc) to conditional javascript based on user permissions.

我只是想我可以提供它,如果它是一个模板,但有url作为我的javascript文件。是这样做的唯一办法吗?

I just had a thought that maybe I can serve it up as if it were a template but have the url as my javascript file. Is that the only way to do somethign like this? If so, it probably wouldn't work with my media generator, so I'd probably want a better solution if there was one out there.

推荐答案

如何在之间的Django HTML模板中定义脚本样式标签之间的JavaScript变量和CSS属性?我知道这听起来像一个黑客,但在我看来一个整洁的,因为这将允许你从一个地方控制你的动态变量。

How about defining the JavaScript variables and CSS attributes from within your Django HTML template, between script and style tags? I know it sounds like a hack, but it seems to me a tidy one, as this will allow you to control your dynamic variables from one spot.

这篇关于Django - javascript和css文件中的模板标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆