Django 3 installed_app shows ModuleNotFoundError in custom folders - django

while using customized folders, I am having a trouble using my app correctly in Django 3. My folder levels are:
--manage.py
--mdtour
----settings
-------settings.py
----apps
------core
----templates
In core app my apps.py file is:
from django.apps import AppConfig
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'
But i cannot use my app in Django 3. In settings file I tried to add the app in two ways:
INSTALLED_APPS = [
'mdtour.apps.core.apps.CoreConfig.core'
]
The error I get:
`ModuleNotFoundError: No module named 'mdtour.apps.core.apps.CoreConfig'; 'mdtour.apps.core.apps' is not a packa`ge
or
INSTALLED_APPS = [
'mdtour.apps.core'
]
this time I get:
django.core.exceptions.ImproperlyConfigured: Cannot import 'core'. Check that 'mdtour.apps.core.apps.CoreConfig.name' is correct.
How can I correct this error?
Thanks

Either just name the module if you're running Django 3.2 (automatic AppConfig discovery):
INSTALLED_APPS = [
'mdtour.apps.core'
]
Alternately, name the appconfig class.
INSTALLED_APPS = [
'mdtour.apps.core.apps.CoreConfig'
]

Related

virtualenv raises importerror because of changing app name in django

I've used [this link] to rename my django app. So I've edited some files and table's name and so on. But as it has been mentioned in that link, There is problem with virtualenv. So how can I fix it? I've change name "notes" to "blog".
The apps.py file:
from django.apps import AppConfig
class NotesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'
In the settings.py file:
INSTALLED_APPS = [
'blog.apps.BlogConfig',
// the rest installed apps
]
Lets say the name of this application is: blog and its following the normal folder structure django comes with.
so, the settings.py should be
INSTALLED_APPS = [
'blog',
]
and the apps.py should be
from django.apps import AppConfig
class BlogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blog'

Cannot import <app>. Check that <path> is correct

I have a next structure of project
I want to create a signal in a blog application, but I get an error
Cannot import 'blog'. Check that 'project.blog.apps.BlogConfig.name'
is correct.
If I write default_app_config = 'blog.apps.BlogConfig' in __init__.py I get error:
No module named 'blog'
settings.py
INSTALLED_APPS = [
#...
# project apps
'project.blog',
#...
]
apps.py
class BlogConfig(AppConfig):
name = 'blog'
def ready(self):
import blog.signals
__init__.py
default_app_config = 'project.blog.apps.BlogConfig'

Django Installed Apps - path full/partial

I was creating this django project and it has a class named "jobs". Now how do i add this "jobs" app in my setting.py. Some say we need to add full path like
INSTALLED_APPS = [
'jobs.apps.JobsConfig'
]
and some say just add the app name like
INSTALLED_APPS = [
'jobs'
]
can anyone tell me which is correct please?

Customizing Django Admin's verbose_name by init, using default

As I would use in version 2 of django the
default_app_config = 'catalog.apps.CatalogConfig' in __init__ to set verbose_name and customize django admin? It returns the error
'No Module named catalog'
Details: I use my apps to a directory below and in INSTALLED_APPS I put projectName.AppName
Your question isn't much clear (to me). What I understood is, you tried to customize the admin interface by adding verbose_name and during that process you got the error, 'No Module named catalog'.
If that so,
Initial you have to put the verbose_name name in your apps configuration class inside the apps module
# catalog/apps.py
from django.apps import AppConfig
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Fantasy Title'
and in your INSTALLED_APPS of settings.py, it should be either
INSTALLED_APPS = [
'catalog',
.....
]
OR
INSTALLED_APPS = [
'catalog.apps.CatalogConfig',
.....
]

"polls.apps.PollsConfig" and "polls" in `INSTALLED APPS'

To tell Django which apps are installed, the official documentation introduces
The advantage 'polls.apps.PollsConfig' over 'polls'
setting.py
INSTALLED_APPS = [
#my APPs
"polls.apps.PollsConfig",
]
This explicitly refer to the installed app in app.py
from django.apps import AppConfig
class LearningLogsConfig(AppConfig):
name = 'learning_logs'
However, in some books, it tell it in a shortcut
setting.py
INSTALLED_APPS = [
#my APPs
"polls",
]
How Django access 'polls' in this situation?
Django can use either option. The version with the AppConfig lets you point Django specifically to an application configuration class which lets you specify some additional config for the app.
If you just want the app as-is, refer to it by its name alone. Use the AppConfig variant only when you are supplying an AppConfig class to configure something about the application.
In the manage.py location Django will check with the string you have given in installed apps list.
Each string should be a dotted Python path to:
an application configuration class (preferred), or
a package containing an application.