Django不会刷新静态文件 [英] Django won't refresh staticfiles

查看:301
本文介绍了Django不会刷新静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很烦人。我在Django模板上引用了一个javascript文件:

This is annoying. I have a javascript file referenced on a django template:

 <script src="{% static 'js/login.js' %} "></script>

我对该js文件做了一些更改。然后,我刷新页面,但看不到更改的发生。

I made some changes to that js file. Then, I refresh the page and I can't see the changes happen.

如果我从文件中删除了javascript并将其放在HTML中,则它可以正常工作,但是,如果我尝试使用外部js文件执行此操作,则不会。我已经尝试过多次关闭服务器并运行runserver,也尝试过从Firefox更改为Chrome。这根本没有意义。请帮助我理解,我可以避免将所有js包含在HTML内,但令我烦恼的是,我无法再以正常的方式进行操作了。

If I remove the javascript from the file and put it in the HTML, it works correctly, but if I try to do it using the external js file then it doesn't. I have tried closing the server and running runserver several times, I've also tried changing from Firefox to Chrome. It makes no sense at all. Please help me understand, I can get away with including all the js inside the HTML but it bothers me that I can't do it the normal way anymore.

更多详细信息关于此错误(我发现的#$&%#最奇怪的东西):

More details about this error (the #$&%# weirdest thing I've found):

javascript是这样的:

The javascript is something like this:

old_sentence = "Dig that hole, forget the sun"  // this is what I want to change
$("#jqselector").text(old_sentence)

new_sentence = "Run, rabbit, run"  // this is the new sentence, it just won't show up.

因此,我更改了js并重新启动了服务器,但html仍然显示了旧句子。然后,我删除了对login.js文件的引用,并将所有js放在HTML的脚本标签中,当然会出现新的句子。然后,我包含login.js文件,将html内的js注释掉,但我删除了login.js文件内的所有内容,使其成为一个空文件...但旧句子仍然显示。因此,旧的login.js文件必须在我不知道的地方兑现。然后,我打开Chrome浏览器,然后再试一次,同样的问题。

So, I changed the js and restart the server, still the html shows the old sentence. Then I deleted the reference to the login.js file and put all the js inside script tags in the HTML, of course, the new sentence appears. Then I include the login.js file, comment out the js inside the html BUT I delete all the content inside the login.js file, making it an empty file... but the old sentence still shows up. Therefore the old login.js file must be cashed somewhere I don't know. Then I open Chrome and try it all again, same problem.

那是什么?是否有强制django刷新staticfile的选项?我认为重新启动服务器就足够了。 ..我应该重新启动计算机吗? :/哈哈。

What can it be? is there an option to force django to refresh staticfiles? I thought restarting the server was enough. .. should I reboot my computer? :/ lol.

推荐答案


  • 清除静态文件 python manage .py collectstatic --noinput --clear

    清除浏览器缓存

    添加随机变量js文件后的字符串包括,例如jquery.js?rand = 23423423,每次加载。

    Add a random string after the js file include, e.g jquery.js?rand=23423423, with each load.

    对它有帮助吗?

    这篇关于Django不会刷新静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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