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:1 by Tim Graham, 8 years ago

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.

Version 0, edited 8 years ago by Tim Graham (next)

comment:2 by Jimmy Merrild Krag, 8 years ago

Summary: Detect management command contextDetect web server command context

comment:3 by Jimmy Merrild Krag, 8 years ago

But what if the project is not served through wsgi?

comment:4 by Jimmy Merrild Krag, 8 years ago

Summary: Detect web server command contextDetect web server context

comment:5 by Tim Graham, 8 years ago

How else do you run a project?

comment:6 by Aymeric Augustin, 8 years ago

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 by Jimmy Merrild Krag, 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 Jimmy Merrild Krag, 8 years ago

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