对(静态)CSS文件的更改未反映在Django开发服务器中

编程入门 行业动态 更新时间:2024-10-09 02:22:45
本文介绍了对(静态)CSS文件的更改未反映在Django开发服务器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Django开发一个Web应用程序,但是在获取CSS文件(存储在我的应用程序的静态目录中)中所做的更改以反映到开发服务器时遇到了一些麻烦。

I am making a Web app using Django and was having some trouble getting the changes made in the CSS file (which is stored in the static directory of my app) to reflect onto the development server.

为清楚起见,服务器能够访问静态文件,但是,它目前停留在CSS文件的旧版本中。几周前发生了类似的问题,当时我没有显示对CSS文件的任何更改。几天后,这个问题就解决了。

To be clear the server is able to access static files, however, it is currently stuck on an old iteration of my CSS file. A similar problem had occurred a few weeks ago, when any change I made to the CSS file wasn't showing up. That problem fixed itself after a few days.

但是,没有立即获得视觉反馈会非常令人沮丧。我已经尝试了以下所有方法来纠正此问题:

However, not getting immediate visual feedback is extremely frustrating. I have tried all of the following to rectify the problem:

  • 我的DEBUG设置为 True
  • 我提供了一个STATIC_URL
  • 我尝试收集静态文件。该命令有效,但开发服务器仍未反映对CSS文件所做的更改
  • 我提供了STATIC_ROOT,STATICFILES_DIR和STATICFILES_FINDER。目前,这些注释已被注释掉,因为我意识到其中一些仅用于生产或对于开发是不必要的。
  • My DEBUG is set to 'True'
  • I have provided a STATIC_URL
  • I tried 'collecting' the static files. The command worked but the dev server is still not reflecting changes made to the CSS file
  • I provided a STATIC_ROOT, STATICFILES_DIR and STATICFILES_FINDER. Currently these are commented out as I realized some of these are for production only or are unnecessary for development.

我的静态资源保存在我的一个应用程序的静态目录- post_it_gen,它是项目的一部分。根据文档,这应该由Django自动搜索。

My static resources are kept in the 'static' directory of one of my apps -- 'post_it_gen' which is part of the project. According to the documentation this should be automatically searched by Django.

任何新建议将不胜感激。

Any new suggestions would be greatly appreciated.

推荐答案

如果您使用Django的服务器进行本地开发,则无需使用 collectstatic 命令,它仅意味着将所有静态依赖项收集到您可以将真实服务器指向的单个访问点,例如apache,lighttpd,nginx等。

If you develop locally using Django's server there's no need to use the collectstatic command, it is only meant to collect all static dependencies to a single access point where you can point your 'real' server to, e.g. apache, lighttpd, nginx etc.

对于您的问题,您暗示它神奇地在几天后自行修复。您是否尝试过重置浏览器的缓存?

As for your problem, you insinuate it 'magically' fixes it self after a few days. Have you tried resetting your browser's cache?

更多推荐

对(静态)CSS文件的更改未反映在Django开发服务器中

本文发布于:2023-11-01 11:06:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   器中   文件   CSS   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!