生成动态 CSS
处理用户定制的样式的最佳方法是什么?作为我正在寻找的结果的一个示例,这就足够了:
body {
color: {{ user.profile.text_color }};
}
但是,将 CSS 作为视图提供似乎会在不断请求的文件中造成大量开销,因此这可能不是一个好的解决方案。
用户无权访问 CSS 文件,我们必须假设他们没有 Web 开发知识。
What is the best way to handle style that that is user-customized? Just as an example of the result I'm looking for, this would suffice:
body {
color: {{ user.profile.text_color }};
}
However, serving CSS as a view seems like it would cause a significant amount of overhead in a file that is constantly requested, so this is probably not a good solution.
The user does not have access to the CSS files and we must assume that they have no web development knowledge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您生成一次 CSS 会怎样?
/common/css.css
元素指向
/user-specific/123.css? ts=123123123
。123
当然是成员的标识符,ts
参数包含时间戳 - 最后一次 CSS 修改的日期304 Not Modified
标头进行回复 - 无需执行任何脚本或下载内容ts
- 再次只需要一个请求And what if you would generate that CSS once?
/common/css.css
<link />
elements points to/user-specific/123.css?ts=123123123
.123
is of course an identifier of the member, andts
parameter contains a timestamp - a date of last CSS modification304 Not Modified
header - there is no need for any script execution or contents downloadts
- once again just a single request is needed像平常一样通过视图动态执行 CSS,但使用积极的缓存,以便它加载速度很快。
Do the CSS dynamically via a view as normal, but use aggressive caching so that it loads quickly.
你可以尝试 django mediagenerato,实际上我读了这个问题,我正在寻找像你一样的解决方案,然后我发现 Django-mediagenerator
我还没有尝试过,但它似乎是一个解决方案。
You can try django mediagenerato, actually I read this Q and I was searching for solution like you, then I found that Django-mediagenerator
I didn't tried it yet but it seams to be a solution.