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'
Related
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'
]
I have a Django DRF application. Here is my project structure.
myproject/
myproject/
apps/
myApp1/
__init__.py
apps.py
admin.py
models.py
urls.py
views.py
myApp2/
__init__.py
static/
manage.py
and myINSTALLED_APPS contains:
INSTALLED_APPS = [
'apps.myApp1.apps.AppOneConfig',
'apps.myApp2.apps.AppTwoConfig',
]
When I went to ./manage.py shell_plus and run:
SomeModel._meta.label
I see myApp1 or myApp2 instead of apps.myApp1 && apps.myApp2. And even in migrations Models are referred as myApp1.Model or myApp2.Model not as apps.myApp1.Model or apps.myApp2.Model
Also, specified AppConfig.
from django.apps import AppConfig
class AppOneConfig(AppConfig):
name = 'apps.myApp1'
verbose_name = 'My App One'
Is that expected ? I am pretty new to Django. Can anyone suggest what the mistake was?
Is that expected?
Yes, that is expected. By default, the app label uses the last part of the "python path". You can change it by specifying this in the AppConfig [Django-doc]. It is the .label attribute [Django-doc] of this AppConfig that determines the app label, and:
(…) It defaults to the last component of name. It should be a valid Python identifier. (…)
Now the .name attribute [Django-doc], and this is:
Full Python path to the application, e.g. 'django.contrib.admin'.
You can specify this by first specifying the AppConfig in the __init__.py file of your myApp1 directory:
# apps/myApp/__init__.py
default_app_config = 'apps.myApp.apps.App1Config'
then you make a file apps.py in the myApp1 directory, and write:
# apps/myApp/apps.py
from django.apps import AppConfig
class App1Config(AppConfig):
label = 'apps_myapp1'
Note: normally directories use slug_case, so I think it might be better to rename your myApp1 to myapp1 or my_app1.
EDIT: You thus need to set the label attribute of your AppOneConfig to:
class AppOneConfig(AppConfig):
name = 'apps.myApp1'
label = 'apps_myapp1'
verbose_name = 'My App One'
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'
I want to know what is the meaning of "Config" in installed_apps in django like this
'polls.apps.pollsConfig'
Is it okay to put only the name of the apps example 'sample_apps'?
In the subfolder polls you have a file apps.py with a class named PollsConfig
polls/apps.py
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
verbose_name = 'PollsApp'
This file is autogenerated by django when you create a new class but you can modify it to add some proprieties.
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',
.....
]