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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27254>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:2>
Comment (by Jimmy Merrild Krag):
But what if the project is not served through wsgi?
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:3>
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:4>
Comment (by Tim Graham):
How else do you run a project?
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:5>
Comment (by Aymeric Augustin):
AFAIK the three supported ways to use Django are:
1. running a WSGI server with the documented WSGI API
2. running management commands with django-admin (or manage.py)
3. `django.setup(); do_stuff()`
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:6>
Comment (by Jimmy Merrild Krag):
`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.
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:7>
* status: new => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/27254#comment:8>