hello guys what the difference between this two syntax
'blog' and 'blog.apps.BlogConfig'
in project this is located in installed app.
I think both are same but there should be difference between this 2 commands because they looks like different
first one is this
INSTALLED_APPS = [
'blog',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
seccond one is :
INSTALLED_APPS = [
'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
I assume that you have a custom configuration(BlogConfig) for your app.
You have at least two options to register the app with custom config in project settings(INSTALLED_APPS).
(if)You have a variable default_app_config = 'blog.apps.BlogConfig' in blog/__init__.py file, then inserting blog into INSTALLED_APPS will be the same as blog.apps.BlogConfig. If you don't have it in __init__.py, BlogConfig won't be applied in the example below.
INSTALLED_APPS = [
...,
'blog',
...,
]
(if)You have an empty __init__.py in your app. Then to apply the custom config you must include the path to config.
INSTALLED_APPS = [
...,
'blog.apps.BlogConfig',
...,
]
putting only blog in the second example will work without the custom config.
Related
I am using djano-environ for my settings
In django development i am planning to install django-extensions app which i need only in development. So what is the recommended way to use django-environ for prod and dev w.r.t INSTALLED_APPS
I have to add it to the INSTALLED_APPS.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# third party apps
'django_extensions',
]
Now how to use django-envion's .env file which will pass INSTALLED_APPS
because i will have a different .env files for dev and prod
I have separate dev.py and prod.py since I've config keys which are not applicable in both the environments.
If you've multiple cases like this a good option would be to create a dev.py
dev.py
from base import *
INSTALLED_APPS += ['django_extensions', ]
Else if this is a one off case, you can load additional app list from your env file.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] + os.list('ENV_SPECIFIC_APPS')
envfile
.
.
ENV_SPECIFIC_APPS=django_extensions
I am following some of the Django courses and these courses have different formats for some specific code parts.
This is the one of them. For example, in the Installed_Apps part of settings.py, what is the difference between writing;
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_pdb',
'polls.apps.PollsConfig',
]
or
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_pdb',
'polls',
]
Thank you for your time and your answers.
In my project, I try to enforce logging format for apps that are not imported as packages but created within project by my fellow devs (as logs from these apps can contain user-sensitive data).
For this, I created a logging.Filter that checks if the LogRecord has the name of the module and then conditionally modifies it.
For example, if this is my app list (part of it):
INSTALLED_APPS = [
# django-supplied
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# third-party apps
'webpack_loader',
'django_tables2',
'django_s3_storage',
# user-created apps
'nlp',
'catalog',
'broker',
]
then the filter checks if the LogRecord.name starts with any of ['nlp', 'catalog', 'broker'].
The question is, how do I detect user-created apps without hardcoding their names into the filter?
The most reliable way would be to hardcode it. But you can do that in your django settings file which would be explicit and maintainable.
# settings.py
CORE_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
]
THIRD_PARTY_APPS = [
'webpack_loader',
'django_tables2',
'django_s3_storage',
]
USER_CREATED_APPS = [
'nlp',
'catalog',
'broker',
]
INSTALLED_APPS = CORE_APPS + THIRD_PARTY_APPS + USER_CREATED_APPS
# customfilter.py
from django.conf import settings
if any(LogRecord.name.startswith(user_app_name)
for user_app_name in settings.USER_CREATED_APPS):
...
the error I've got is :
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
My setting file is like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'disqus',
]
SITE_ID = 1
DISQUS_API_KEY = 'kLA0JWWljFwKTHvSym2oSRIlBSDCZZmReyx9NeIzPz48rtwS6Ew2vVewmZgupsea'
DISQUS_WEBSITE_SHORTNAME = 'foobar'
I'm using oscar and added from fork order app. After added that cant run syncdb or server. It is giving an error import error: No module named 'project\\order'
from oscar import get_core_apps
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.sites',
'compressor',
] + get_core_apps(['project\order'])
SITE_ID = 1
this is my installed apps. I didnt understand why it doing this.
This get_core_apps(['project\order']) should be get_core_apps(['project.order']).
I changed project to oscar.apps.order and it did work. But why, it is a question for me.