django 压缩器和 smartcss 具有绝对 url 路径
当使用 django、compressor 和 smartcss 时,我将 css url 设置为绝对路径。然后向 Clevercss 传递不带 COMPRESS_ROOT 前缀的 .ccss 文件的路径(绝对路径)。当我将 css url 设置为相对路径时,clevercss 会处理 ccss 文件,但浏览器会正确查找相对放置的 css 文件(例如 mywebsite.com/profile/user/1/css/stylesheet.css)
压缩机,但是,当 css 链接是相对 url 时,确实使用 MEDIA_ROOT,但使用绝对 url 时则不使用。这会产生不幸的效果,因为我的 css 要么由 smartcss 渲染,并且浏览器无法访问(除非在主页上),要么 smartcss 无法访问文件(由于使用了绝对 url)。讽刺的是, http://github.com/mintchaos/django_compressor 上提供的示例使用 CSS 的绝对 URL路径。
我认为我在这里做错了什么,但我不确定它可能在哪里,并且花了几个小时寻找。我目前还通过 ./manage.py runserver 在本地运行它,并通过 django 提供一些静态文件(图像)。 (这对我当地的发展来说很好)。
When using django, compressor, and clevercss, I set my css url to an absolute path. Clevercss is then passed the path of the .ccss file without the COMPRESS_ROOT prefixed (the absolute path). When I set my css url to a relative path, clevercss processes the ccss files, but the browser then correctly looks for relatively placed css files (e.g. mywebsite.com/profile/user/1/css/stylesheet.css)
Compressor, however, does use the MEDIA_ROOT when the css link is a relative url, but not when an absolute url is used. This has the unfortunate effect of my css either being rendered by clevercss and not accessible by the browser (unless on the home page), or clevercss not having access to the files (due to an absolute url being used). Ironically, the examples offered on http://github.com/mintchaos/django_compressor use absolute urls for the css paths.
I think I'm doing something wrong here, but I'm not sure where it could be and have spent quite a few hours looking. I'm also currently running this locally through ./manage.py runserver and serving some static files (images) through django. (this is fine for my local development).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能具体谈论 django-compressor;但我一直在为 Django 支持的 Web 应用程序的 CSS 和 JS 文件寻找一个好的自动压缩解决方案。我目前正在使用 django-static。 IMO,它的设置和使用非常简单。当我决定尝试 django-static 时,我在运行 django-compress(与 django-compressor 不同)时遇到了一些问题。到目前为止,一切都很棒。可能值得一看。可以在这里找到:http://github.com/peterbe/django-static。
I can't speak to django-compressor specifically; but I have been dealing with finding a good automatic compression solution for the CSS and JS files of my Django-powered web applications. I'm currently using django-static. It's been really easy to set up and use, IMO. I was running into some issues running django-compress (different from django-compressor) when I decided to give django-static a try. So far it's been great. Might be worth checking out. It can be found here: http://github.com/peterbe/django-static.