Can I configure a reboot of the Django server when changing static or non-python files?

By default, the Django command runserverautomatically restarts the server when python files change or template.

Is it possible to configure Django to continue to control files for this purpose in other directories or file sets such as JavaScript or CSS files to be used statically (during development)?

This would be useful in this scenario: the Django application reads a set of static text files at startup, and I would like the server to re-read them when they change, without the need to add this specific function - just restarting would be fine.

Do I need to start interfering with (or expanding) django/utils/autoreload.py?

+4
source share
4 answers

By default, the file will be read from the disk for each request, so there is no need to restart anything.

There is a cache template loader, but it is disabled by default. See the documentation for more information.

0
source

As the commentary to your question says, Django always pulls a file from the file system for each request, so they are not cached.

However, there is a check (in django.views.static) for the mtime file if the browser sends an If-Modified-Since header, so you can see 304 Not Modified.

Regardless of whether it is easy to disable browser caching that meets your needs?

0
source

, dev.

... , :

Ctrl + Shift + r   Ctrl + f5

Mac CMD ctrl

0

, .

collectstatic , (, javascript) , .

:

  • ( "" )
  • :

python manage.py collectstatic --noinput

then your server will see all the changes in the files.

0
source

All Articles