Django installed_apps does not recognise my app? - django

This is my installed apps section in settings.py.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'homepage.apps.HomepageConfig',
.
.
.
]
My app name is "homepage" and I really can't remember why I changed it to 'homepage.apps.HomepageConfig', but whatever it is, it worked on my machine.
Now, i uploaded my files to server, installed required apps, did the migrations, but i noticed django does not create my "homepage" app table and does not migrate anything from my app. And my website returns the error: table homepage_post does not exist.
What is wrong?

Check if in homepage app directory You have file named __init__.py and apps.py. The content of apps.py should be:
from django.apps import AppConfig
class HomepageConfig(AppConfig):
name = 'homepage'

Related

AUTH_USER_MODEL reference in settings.py Django

I have a installed an app called 'Login', who have a folder 'models' inside, with a custom_user model. The problem occurs when I tried to configure settings.py, specially auth_user_model.
in installed apps I have the following:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'project_app.login'
]
and below
AUTH_USER_MODEL = 'login.models.CustomUser'
But I have the following error: "Invalid model reference. String model references must be of the form 'app_label.ModelName'." I put the .models in AUTH_USER_MODEL, because I want to reference the app that the CustomUser is inside the folder "models" in Login.
Also, I tried with declare like this:
AUTH_USER_MODEL = 'login.CustomUser'
but the error is this: 'AUTH_USER_MODEL refers to model 'login.CustomUser' that has not been installed'
The issue is with the way that your app is installed - based on your AUTH_USER_MODEL, login should be the name of the app. It is acceptable to contain Django apps within folders for organisation purposes - however, your parent folder is project_app which from the name also appears to be an app. It's hard to say for certain what the issue is without knowing your project structure but I would expect changing your installed apps to just project_app and your AUTH_USER_MODEL to project_app.CustomerUser should work.
If your app name is "login", you can proceed as follows:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
#apps
'login.apps.LoginConfig']
I think the model in your login application is as follows:
class CustomUser(AbstractBaseUser):
#some fields for customuser
and in settings.py:
AUTH_USER_MODEL = 'user.CustomUser'
AUTH_USER_MODEL = 'app_name.ModelName'

Struggling with adding app to INSTALLED_APPS Django

I have no idea, this always worked for me, but without motivation, it's not working now.
what i did:
I created my project
I created my app
I added my config to INSTALLED_APPS
I get this error: django.core.exceptions.ImproperlyConfigured: 'champ.apps' does not contain a class 'ChampConfigcorsheaders'. Choices are: 'ChampConfig'.
My project looks like this:
Championship_3bi
champ
all the files of the app
Championship_3bi
all the files of the project
This is my settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'champ.apps.ChampConfig' #this is the line that create the "error"
'corsheaders',
]
I've also tried to do champ.apps.ChampConfigcorsheaders but it didnt work.
This is my champ/apps.py:
from django.apps import AppConfig
class ChampConfig(AppConfig):
name = 'champ'
i searched for everything but looks like i was the only one who get this error.
The reason why it does not work is for the weird name of my project?
Why it is not working for only this project?
im done
You are missing a ,:
'champ.apps.ChampConfig',
'corsheaders',

ModuleNotFoundError when registering django app

I'm getting an error when I include my app in the settings.py file using <app>.apps.PagesConfig. I'm in a virtual environment, have the project and app installed, and the app has an __init__.py inside. If I just register it as <app>, it works, but not with the full <app>.apps.PagesConfig See code and error below.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_test.apps.PagesConfig',
]
Error:
ModuleNotFoundError: No module named 'app_test.apps.PagesConfig'; 'app_test.apps' is not a package
'app_test.apps.AppTestConfig',
this would be the one that you need to put in the settings, the Class Name which is there in the apps.py not some random name
You have to create a file apps.py which would contain a class PagesConfig to make this work. For example app_test/apps.py could look like:
from django.apps import AppConfig
class PagesConfig(AppConfig):
name = 'My pages'
See the Django application documentation.

ValueError - How to Extend OAuth2 Application Model - Django

I want extend Application model of django oauth toolkit. They have given intsructions here link
But i am not getting how to do it. I have created one app inside apps folder and inside models i have added the following code.
from django.db import models
from oauth2_provider.models import AbstractApplication
class MyApplication(AbstractApplication):
logo = models.ImageField()
agree = models.BooleanField()
Resgitered the app inside installed_apps as 'apps.oauth2', and added the following line:
OAUTH2_PROVIDER_APPLICATION_MODEL='apps.OAuth2'
But it giving me error
LookupError: No installed app with label 'apps'.
Installed Apps [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'apps.commons',
'apps.company',
'apps.oauth2',
]
According this manual link model in OAUTH2_PROVIDER_APPLICATION_MODEL should be class name not app

Django 1.10 - Plug new app into django

I have a trouble with plugging recently created app called pages into a django project.
My pages apps.py
from django.apps import AppConfig
class PagesConfig(AppConfig):
name = 'pages'
My settings.py, installed apps:
INSTALLED_APPS = [
'pages.apps.PagesConfig' # pages.apps.pages fails too
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
ImportError: No module named 'pages.apps.PagesConfigdjango';
'pages.apps' is not a package
Does anyonw knows what is wrong there? I did everything according the docs, but django still cannot to plug my app. Any insights appreciated.
You are missing a comma after your entry.
'pages.apps.PagesConfig',