Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPuffy wuff
9,573 PointsQuestion about django settings - installed apps
When I'm adding my installed apps to the django settings file i usually do this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# my app
'pages',
]
But Ive noticed some people doing this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# not sure about this thing
'pages.apps.PagesConfig',
]
I'm not sure what this is - Ive never used this apps.py file before. Should I be using this?
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Puffy Wuff,
What you are seeing is a newer way (since about v1.7 of Django) of declaring installed apps in your settings.py file.
You have the choice of either listing the application module (what you have been doing before) or describing a particular class that derives from AppConfig which can provide more control over the application (what you are seeing in the above example).
As far as I am aware there is no plan to deprecate the old (easier) way of declaring installed apps, so if that works for you, keep on doing it. Just be aware that the option exists to specify a specific config class that will give you some extra flexibility if you need it. Specifically:
- you can have multiple apps in the same module;
- you can specify an app configuration in a file;
- you can subclass that configuration to make different instances of the app behave differently.
If you are interested, you can read more in the official docs
Cheers
Alex