File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ You will need to include ``devserver`` in your ``INSTALLED_APPS``::
3434 'devserver',
3535 )
3636
37+ If you're using ``django.contrib.staticfiles `` or any other apps with management
38+ command ``runserver ``, make sure to put ``devserver `` *above * any of them (or *below *,
39+ for ``Django<1.7 ``). Otherwise ``devserver `` will raise exception to ensure it is set up
40+ properly.
41+
3742-----
3843Usage
3944-----
Original file line number Diff line number Diff line change 1+ import django
12from django .core import exceptions
3+ from django .core .exceptions import ImproperlyConfigured
24
35from devserver .logger import GenericLogger
46
57
68MODULES = []
79
810
11+ def check_installed_apps_configuration ():
12+ """
13+ Check the app is put in correct order in INSTALLED_APPS
14+
15+ django.contrib.staticfiles runserver command is likely to
16+ override devserver management command if put in wrong order.
17+
18+ Django had reversed order of management commands collection prior to 1.7
19+ https://code.djangoproject.com/ticket/16599
20+ """
21+ from django .conf import settings
22+ try :
23+ staticfiles_index = settings .INSTALLED_APPS .index ('django.contrib.staticfiles' )
24+ devserver_index = settings .INSTALLED_APPS .index ('devserver' )
25+ except ValueError :
26+ pass
27+ else :
28+ latest_app_overrides = django .VERSION < (1 , 7 )
29+ if devserver_index < staticfiles_index and latest_app_overrides :
30+ raise ImproperlyConfigured (
31+ 'Put "devserver" below "django.contrib.staticfiles" in INSTALLED_APPS to make it work' )
32+ elif devserver_index > staticfiles_index and not latest_app_overrides :
33+ raise ImproperlyConfigured (
34+ 'Put "devserver" above "django.contrib.staticfiles" in INSTALLED_APPS to make it work' )
35+
36+
937def load_modules ():
1038 global MODULES
1139
@@ -37,4 +65,5 @@ def load_modules():
3765 MODULES .append (instance )
3866
3967if not MODULES :
68+ check_installed_apps_configuration ()
4069 load_modules ()
You can’t perform that action at this time.
0 commit comments