django 1.10 list of installed apps

541 views Asked by At

So I'm trying this:

import my_project.settings
DEVOPS_APPS = [ app for app in my_project.settings.INSTALLED_APPS if not "django" in app ]

Sometimes when I refresh, the data doesn't show.

Other times when I refresh, the data shows.

Still some other times when I refresh, I get the full list of INSTALLED_APPS

My index function looks like so:

template = loader.get_template('dashboard/index.html')
      context = {
        'title': "Telematics DevOps Automation Team",
        'installed_apps': DEVOPS_APPS,
        'server': 'atllvasbap001i.hughestelematics.net',
        'charts': data['charts']
        }
return HttpResponse(template.render(context))

What am I doing wrong?

1

There are 1 answers

0
cuerty On BEST ANSWER

When using settings, django recommends importing django.conf.settings instead of importing your settings module:

from django.conf import settings
[app for app in settings.INSTALLED_APPS if not 'django' in app]
# will output
# >>> [u'user_auth', u'payment', u'logistic', u'art', u'home', 
#      u'swipe', u'easy_thumbnails', u'crispy_forms', u'floppyforms',   
#      u'rest_framework', u'rest_framework.authtoken', 
#      u'adminsortable']

A recommended read on this is Using settings in Python code.