Opened 8 years ago
Closed 8 years ago
#27254 closed New feature (wontfix)
Detect web server context
Reported by: | Jimmy Merrild Krag | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have some code in my project that generates some content for my pages (compiles documentation).
I would like this code to run once every time the server starts, and essentially I should use AppConfig.ready()
to do this. However AppConfig.ready()
also runs when I run any management command, which is very undesirrable, as I don't want to generate this content every time I run unrelated tasks, such as migrate
.
Therefore it would be nice to have a flag or some other means to detect if code is currently running in the context a web server or not.
For now I have implemented this as a middleware which throws MiddlewareNotUsed
after generating the content.
Change History (8)
comment:2 by , 8 years ago
Summary: | Detect management command context → Detect web server command context |
---|
comment:4 by , 8 years ago
Summary: | Detect web server command context → Detect web server context |
---|
comment:6 by , 8 years ago
AFAIK the three supported ways to use Django are:
- running a WSGI server with the documented WSGI API
- running management commands with django-admin (or manage.py)
django.setup(); do_stuff()
comment:7 by , 8 years ago
python manage.py runserver
during development, but you make a valid point. Need to test if I can run my things there then, and then i guess developers must just run a management command manually to build documentation.
comment:8 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
What about putting the code to be run when the server starts in
wsgi.py
? I'm not so sure if the prosed "context" idea is feasible.