Django: Accessing reusable app in settings.py - python

I have a reusable django app installed in my project, and the desired outcome is to import it into the main project's settings.py.
The project runs well with the reusable app installed and added into INSTALLED APPS in settings.py.
However, when I try to import it in settings.py, django throws an error.
#import statement
from config_table.models import *
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
..., #other apps
'config_table', #reusable app
... #other apps
]
Error Traceback:
Traceback (most recent call last):
File "C:\Users\repo\Auth\auth\manage.py", line 22, in <module>
main()
File "C:\Users\repo\Auth\auth\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\core\management\__init__.py", line 386, in execute
settings.INSTALLED_APPS
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\conf\__init__.py", line 87, in __getattr__
self._setup(name)
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\conf\__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\conf\__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\repo\Auth\auth\auth\settings.py", line 52, in <module>
from config_table.models import *
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\config_table\models.py", line 1, in <module>
from django.contrib.auth.models import User
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\contrib\auth\models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\contrib\auth\base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\db\models\base.py", line 127, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\apps\registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\repo\Auth\auth\venv\lib\site-packages\django\apps\registry.py", line 138, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I think it has something to do with Django not loading the reusable app in time before the imports, but I'm not sure how to solve this.
Any suggestions are much appreciated!

Related

ImportError: cannot import name 'DEFAULT_CURRENCY' from 'moneyed' on Ubuntu

I've been using Django for just over a year for the development of an automation software and am currently just running the project locally on my windows machine.
I hadn't run into any issues with it, until I tried running cron tasks, which ofc windows doesn't support. Scheduled tasks don't work the same way imo, so I installed a Ubuntu VM to work with the project.
Set everything up correctly(I think?), installed Django and all. Currently installing all the libraries the project uses, one of which is django-money. I have installed it, as well as py-moneyed, yet on trying to make migrations, or run the server, I run into this error
enter image description here
Can't find anything about this online. The project still works perfectly with the windows command prompt, as well as PowerShell but having this issue on the ubuntu VM.
Installed apps on my settings.py look like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap5',
'sass_processor',
'djmoney',
'background_task',
'django_crontab',
'companies',
'google_cal',
'dashboard',
]
Any help on this, or good alternative for corn tasks-need some to run every 2 hours and update the db and others to run once a day at a specific time. Celery also does not work with Windows.
The full error is:
Traceback (most recent call last):
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv
/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 61, in execute super().execute(*args, **options)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 68, in handle if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__ self._setup(name)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup self._wrapped = Settings(settings_module)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__ mod =
importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/mnt/f/Django/RC/Sales-automation/sales-automation/automation_software/automation_software/settings.py", line 16, in <module>
from djmoney.settings import FIXER_ACCESS_KEY
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/djmoney/settings.py", line 6, in <module>
from moneyed import CURRENCIES, DEFAULT_CURRENCY, DEFAULT_CURRENCY_CODE
ImportError: cannot import name 'DEFAULT_CURRENCY' from 'moneyed' (/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/moneyed/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module> main()
File "manage.py", line 18, in main execute_from_command_line(sys.argv)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute()
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/core/management/base.py", line 367, in run_from_argv connections.close_all()
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/db/utils.py", line 208, in close_all for alias in self:
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/utils/connection.py", line 73, in __iter__ return
iter(self.settings)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/utils/connection.py", line 45, in
settings self._settings =
self.configure_settings(self._settings)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/db/utils.py", line 144, in configure_settings databases =
super().configure_settings(databases)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/utils/connection.py", line 50, in configure_settings settings = getattr(django_settings, self.settings_name)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__ self._setup(name)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup self._wrapped = Settings(settings_module)
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed
File "/mnt/f/Django/RC/Sales-automation/sales-automation/automation_software/automation_software/settings.py", line 16, in <module>
from djmoney.settings import FIXER_ACCESS_KEY
File "/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/djmoney/settings.py", line 6, in <module>
from moneyed import CURRENCIES, DEFAULT_CURRENCY, DEFAULT_CURRENCY_CODE
ImportError: cannot import name 'DEFAULT_CURRENCY' from 'moneyed' (/mnt/f/Django/RC/Sales-automation/sales-automation/ubuntu_venv/lib/python3.8/site-packages/moneyed/__init__.py)
That constant has been removed in version 2.0. See this link https://github.com/py-moneyed/py-moneyed/blob/ef5d65da3e6e774a377b6e1434a051f0454d2193/CHANGES.rst

django import export app error: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

I'm upgrading a Django site to 3.1.2 and noticed one backend app wasn't working, in the process of asking the community help in fixing this I found out the app wasn't a custom made code by a single coder for the site but a community project called django-import-export. Since it's up to date and supports django 3.1 i deleted the manual way it was setup as a folder and pip installed it. i then tried to do a makemigrations threw an error and after reading the setup docs assumed possibly you need to do collectstatic first, it also threw the same error
(kpsga) sammy#kpsga:~/webapps/kpsga$ python manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sammy/webapps/kpsga/guides/models.py", line 77, in <module>
class GuideResource(resources.ModelResource):
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/import_export/resources.py", line 930, in __new__
field = new_class.field_from_django_field(f.name, f,
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/import_export/resources.py", line 1079, in field_from_django_field
FieldWidget = cls.widget_from_django_field(django_field)
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/import_export/resources.py", line 1045, in widget_from_django_field
result = getattr(cls, result)(f)
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/import_export/resources.py", line 1025, in get_fk_widget
model=get_related_model(field))
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/import_export/resources.py", line 49, in get_related_model
if hasattr(field, 'related_model'):
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/db/models/fields/related.py", line 95, in related_model
apps.check_models_ready()
File "/home/sammy/webapps/envs/kpsga/lib/python3.8/site-packages/django/apps/registry.py", line 141, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
this somehow is related to installed_apps so I've included the entire list below
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#site apps
'guides',
'pages',
#imported old dependencies
'blog',
'import_export',
'generic',
#imports
'comments_moderation',
'django_comments',
'sorl.thumbnail',
#additional django
'django.contrib.sites',
'django.contrib.humanize',
]
The traceback shows that the error occurs when loading GuideResource in your models.py.
The getting started docs for django-import-export suggest putting the resource in the admin.py, so I would try moving the GuideResource outside of models.py.

Python Django - "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL

If there is any bug in my code (code within a model that is used within a view which uses LoginRequiredMixin ) e.g. A bug like:
if (True: # <-- example bug to show how bugs like this are hidden
Then I get the following error:
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured:
AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
This makes it really hard to debug the code. I have figured out if I remove this line from my views.py:
from django.contrib.auth.mixins import LoginRequiredMixin
Even if I remove all instances where LoginRequiredMixin is used, just by importing it, it hides the true bug and generates the above auth error.
I have read: AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
My research shows most of the time this is due to "django.contrib.auth'" missing from INSTALLED_APPS, which you can see I have (settings.py snippet, Django 2.2):
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth', # <-- Important for this topic!
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp.apps.CommonConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
I tried adding this to above the mixim import but neither helped:
from django.contrib import auth
from django.contrib.auth.models import User
This part of the full traceback agrees with the above:
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'auth'
Here is the traceback if I call makemigrations (This is what I expect):
C:\code\myproject\src>pipenv run python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\code\myproject\src\myapp\models.py", line 14, in <module>
from .sql import myapp_entry_clean, myapp_entry_grouping
File "C:\code\myproject\src\myapp\sql.py", line 68
if (True:
^
SyntaxError: invalid syntax
C:\code\myproject\src>
Here is the traceback with runserver:
C:\code\myproject\src>pipenv run python manage.py runserver
Watching for file changes with StatReloader
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[0](_exception[1]).with_traceback(_exception[2])
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\code\myproject\src\myapp\models.py", line 14, in <module>
from .sql import myapp_entry_clean, myapp_entry_grouping
File "<string>", line None
SyntaxError: invalid syntax (sql.py, line 68)
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 155, in get_app_config
return self.app_configs[app_label]
KeyError: 'auth'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\__init__.py", line 165, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 205, in get_model
app_config = self.get_app_config(app_label)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\apps\registry.py", line 162, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'auth'.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\autoreload.py", line 272, in run
get_resolver().urlconf_module
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\urls\resolvers.py", line 564, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\code\myproject\src\linkcube\urls.py", line 20, in <module>
path('', include('common.urls')),
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\code\myproject\src\common\urls.py", line 5, in <module>
from . import views
File "C:\code\myproject\src\common\views.py", line 9, in <module>
from django.contrib.auth.mixins import LoginRequiredMixin
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\mixins.py", line 3, in <module>
from django.contrib.auth.views import redirect_to_login
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\views.py", line 10, in <module>
from django.contrib.auth.forms import (
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\forms.py", line 20, in <module>
UserModel = get_user_model()
File "C:\Users\User\.virtualenvs\myproject-wc-xNQPL\lib\site-packages\django\contrib\auth\__init__.py", line 170, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
C:\code\myproject\src>
How do I make it so that the auth error is not falsely raised?
So the issue here is a python syntax error, but (maybe) since you are running Django framework, Django suppresses that and throws the missing model error.
Since python is interpreted language it threw an error for SyntaxError and since there was syntax error Django did not find auth model reference.
That's why you see both the errors there, python's SyntaxError and Django's ImproperlyConfigured error.
Django is kind enough to let you know that the Django's error is caused by the python's syntax error.
If you are getting that error message, I belive you are using a custom user model.
You may want to try to use AUTH_USER_MODEL on your relationships instead of the direct model User or the get_user_model method. This pretty much cleared the bug for me.
I got the solution from https://learndjango.com/tutorials/django-best-practices-referencing-user-model
The way to use AUTH_USER_MODEL is by first importing it from the settings usingfrom django.conf import settings and on the field that requires the relationship, you use it as, for example seller = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

Apps not ready yet, upgrading to Django 1.9 and then to 2.0

I am trying to upgrade my Django project to Django 2.0, currently the version is 1.8.19. I figured I would do it step by step, firstly upgrading to 1.9, then 1.10 and so on till 2.0. The problem is that I get error message
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/riddle/tmp1/example-project/app/ad_akumuliatoriai_lt/settings.py", line 140, in <module>
from apps.frontend.ad_akumuliatoriai.models import Language
File "/home/riddle/tmp1/example-project/app/apps/frontend/ad_akumuliatoriai/models.py", line 5, in <module>
from ordered_model.models import OrderedModel
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/ordered_model/models.py", line 20, in <module>
class OrderedModelBase(models.Model):
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I have read the thread: Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet."
I have tried using
import django
django.setup()
at the top of my settings.py file with no luck.
I've made an assumption that the problem is with the third party apps.
My main question is, how to start checking for invalid third party apps, since commenting them out one by one does not remove the error. I've checked every app's that I've installed via pip documentation, and added the required lines
to the INSTALLED_APPS in settings.py. It seems that some packages, such as django-jquery, django-libsass, django-ordered-model have not been developed for some years, however, according to django==1.9 release date, those apps should have worked on django==1.9 (or maybe that is the mistake of my thinking?).
I am ready to post more information from my project if needed.
My settings.py fragment:
INSTALLED_APPS = (
'hvad',
'compressor',
'filebrowser',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'jquery',
'tinymce',
'apps.frontend.ad_akumuliatoriai',
'ordered_model',
'geoposition',
)
The output of "pip freeze":
Django==1.9
django-appconf==1.0.2
django-compressor==2.2
django-filebrowser-no-grappelli==3.7.4
django-geoposition==0.3.0
django-hvad==1.8.0
django-jquery==3.1.0
django-libsass==0.7
django-ordered-model==1.4.3
django-tinymce==2.7.0
libsass==0.14.2
Pillow==5.1.0
psycopg2==2.7.4
pytz==2018.3
rcssmin==1.0.6
rjsmin==1.0.12
six==1.11.0
The traceback suggests you are importing a model in your settings.py:
from apps.frontend.ad_akumuliatoriai.models import Language
You shouldn't do this. Remove the import.

django oscar AppNotFoundError

Im following this tutorial step by step:
http://django-oscar.readthedocs.org/en/releases-1.1/internals/getting_started.html#install-oscar-and-its-dependencies
the thing is when I run the server locally and connect to localhost:8000, I just get this error
Traceback (most recent call last):
File "/usr/lib64/python3.5/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
self.load_middleware()
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/django/core/handlers/base.py", line 50, in load_middleware
mw_class = import_string(middleware_path)
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/home/hit/projects/quesos/oscar/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/oscar/apps/basket/middleware.py", line 8, in <module>
Applicator = get_class('offer.utils', 'Applicator')
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/oscar/core/loading.py", line 29, in get_class
return get_classes(module_label, [classname])[0]
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/oscar/core/loading.py", line 91, in get_classes
installed_apps_entry, app_name = _find_installed_apps_entry(module_label)
File "/home/hit/projects/quesos/oscar/lib/python3.5/site-packages/oscar/core/loading.py", line 197, in _find_installed_apps_entry
"Couldn't find an app to import %s from" % module_label)
oscar.core.exceptions.AppNotFoundError: Couldn't find an app to import offer.utils from
I'm not sure how to make it work. Can any one help?
Thanks.
You have to append Oscar’s core apps to the installed apps, for example:
from oscar import get_core_apps
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
...
'compressor',
'widget_tweaks',
] + get_core_apps()

Categories