Opened 7 years ago

Closed 7 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:1 Changed 7 years ago by Tim Graham

What about putting the code to be run when the server starts in wsgi.py? I'm not so sure if the proposed "context" idea is feasible.

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:2 Changed 7 years ago by Jimmy Merrild Krag

Summary: Detect management command contextDetect web server command context

comment:3 Changed 7 years ago by Jimmy Merrild Krag

But what if the project is not served through wsgi?

comment:4 Changed 7 years ago by Jimmy Merrild Krag

Summary: Detect web server command contextDetect web server context

comment:5 Changed 7 years ago by Tim Graham

How else do you run a project?

comment:6 Changed 7 years ago 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()

comment:7 Changed 7 years ago 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.

comment:8 Changed 7 years ago by Jimmy Merrild Krag

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top