adamchainz / django-browser-reload

Automatically reload your browser in development.
MIT License
507 stars 26 forks source link

Consider adding a mechanism for python code to explicitly force a reload #244

Open davepeck opened 7 months ago

davepeck commented 7 months ago

Description

For instance, I'd like to force a reload when I create or update a specific model instance in my app. Presumably, if django_browser_reload is inactive (DEBUG is False, etc.) then this is a no-op.

Apologies if I simply missed it, but is there an explicitly supported method I can call (or signal I can raise) to achieve this?

adamchainz commented 7 months ago

There isn’t a method. Would this be when you run a management command or something? It could be an interesting addition.

davepeck commented 7 months ago

Yes, this is in the context of a management command — in my case, one that's run while I'm also running a local dev server.

(My inelegant solution at the moment is to have the management command touch an otherwise unused reload.html file sitting in my template hierarchy.)

adamchainz commented 7 months ago

This method would need to call trigger_reload_soon() within the runserver process. If you can figure out some way of doing lightweight cross-process communication to do that, it could work as an addition.

But then again, touching a file, as you’re already doing, is a simple cross-process communication method. So it might not be worth adding anything. FYI you can use Path.touch() as a quick way to do this.

davepeck commented 7 months ago

I pondered this over the weekend and eventually decided it probably isn't worth building an explicit mechanism when touching a file will do fine.

Not sure where you landed but if in the same place then maybe a documentation update to suggest this would be useful?

Other than that, we can probably close this issue. Thanks again...

adamchainz commented 7 months ago

Let's add a documentation section covering touching an existing template.