Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davepeck opened this issue Feb 9, 2024 · 5 comments
Open

Comments

@davepeck
Copy link

davepeck commented Feb 9, 2024

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
Copy link
Owner

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

@davepeck
Copy link
Author

davepeck commented Feb 9, 2024

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
Copy link
Owner

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
Copy link
Author

davepeck commented Feb 12, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants