Django suddenly gives me error that Apps aren't loaded yet - django

I am using Django3.1. All was working fine. I pip installed a new app and tried to run makemigrations. It suddenly doesn't work anymore. I get error 'Apps are not loaded yet'. I thought it was the app. Uninstalled it. Didn't work. Deleted the virtualenv directory. Created new one and installed all apps again except the last one. It didn't work. I had installed another version of Postgres and hadn't restarted my computer since then. Restarted but didn't work. Tested by running another project to make sure it was not new Postgres issue. That worked as expected.
Commented out my url confs and installed apps in the settings.py. But still the same error.
Tried multiple SO suggestion related to this error but nothing works. Can anyone please help.
Error from console:
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 "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\core\checks\translation.py", line 60, in check_language_settings_consistent
get_supported_language_variant(settings.LANGUAGE_CODE)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\__init__.py", line 299, in get_supported_language_variant
return _trans.get_supported_language_variant(lang_code, strict)
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 488, in get_supported_language_variant
if code in supported_lang_codes and check_for_language(code):
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 451, in check_for_language
for path in all_locale_paths()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\utils\translation\trans_real.py", line 428, in all_locale_paths
for app_config in apps.get_app_configs():
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\apps\registry.py", line 145, in get_app_configs
self.check_apps_ready()
File "C:\Users\myuser\Envs\myproject\lib\site-packages\django\apps\registry.py", line 136, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Thanks

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_name', #i hope you added app_name in settings file
or
'app_name.apps.app_nameConfig' #else try this app_name is name of your app,apps is constant key word and you will get class app_nameConfig in apps.py file
]

Related

process to load database in django project

what is the correct process to move a django cms_project to the server?
I create the database from my project like this
./manage.py dumpdata > resource/ddbb/20160817_db.json
I save inside the project in resource file
I move the entire project to the server and after that I execute that command
python manage.py loaddata resource/ddbb/20160817_db.json
But I obtain this error
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named djangocms_admin_style
any idea how to solvent?
Thanks in advances
This error means django cannot find a package named djangocms_admin_style. It seems like you are using django-admin-shortcuts. In that case you have to make sure that djangocms_admin_style and djangocms_admin_style to INSTALLED_APPS of your settings.py after installing djangocms_admin_style with pip`. Use command below to install djangocms_admin_style
pip install djangocms_admin_style
as per docs add 'djangocms_admin_style' to your INSTALLED_APPS just before 'django.contrib.admin'

Django Suit: ImportError: No module named suit

Any suggestions?
I have added this code in settings.py after I install pip install django-suit and ./manage.py collectstatic. Not sure of the error.
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP
TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)
# Application definition
INSTALLED_APPS = (
'suit',)
**error**
heroku run ./manage.py syncdb
Running `./manage.py syncdb` attached to terminal... up, run.8285
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named suit
In case, someone in stuck in the same issue and adding the line "django-suit==0.2.7" in requrements.txt did not work, then please try adding the latest django-suite version name in the requirements.txt file and it should work.
So, your requirements.txt file will have the following line.
django-suit==0.2.13
And then run the following command.
pip install -r requirements.txt
And now, it should work!! ;)
Issue fixed. I add django-suit==0.2.7 in requirements.txt
Don't forget make migrate:
python manage.py migrate

Google App engine, django, userena, database setup

I am trying to build a web app with GAE, Django. The user registration would be userena. I already use the django-nonrel and all the setup to get the first part working and I am trying to syncdb for userena. I am keep getting this errors, Could you please help me on this.
BB8265:epapyri-django$ sudo django-admin.py syncdb
Password:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
settings.py and manage.py are in the same directory and I did not have this issue before adding this plugin.
the settings.py for database section is as follows:
# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'
INSTALLED_APPS = (
# 'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'djangotoolbox',
'autoload',
'dbindexer',
# social_auth
'httplib2',
'openid',
'oauth2',
'social_auth',
#userena
'userena',
'guardian',
'easy_thumbnails',
'accounts',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
and this is once I runserver
BB8265:epapyri-django$ sudo django-admin.py runserver
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/Library/Python/2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Library/Python/2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Library/Python/2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
[edited]
I remove the non django project from INSTALL_APP, import the django.models to my accounts/MyProfile, and chmod 777 on the .datastore since it shouldn't ask for permission every time modify it.
{File "/git/ePapyri/epapyri-django/djangoappengine/db/base.py", line 160, in _value_for_db
raise DatabaseError("Only strings and positive integers "
django.db.utils.DatabaseError: Only strings and positive integers may be used as keys on GAE.}
Why are you using django-admin.py to run syncdb and runserver? You should be using manage.py.
And you should definitely not be using sudo to run either of these.
(Also note your INSTALLED_APPS seems to be nonsense: it contains a whole lot of plain Python libraries like httplib2 and oauth2 which have no business at all being there.)
Edited
Firstly, you should have edited your question to add the traceback.
Secondly, the error message is very clear: you have not imported django.db.models in your accounts/models.py file.
Thirdly, it is still nonsense to include non-Django libraries in INSTALLED_APPS. There is simply no need to do so. And your datastore should not have been created with sudo in the first place - either delete and recreate it, or use chmod to make it accessible to a normal user.
I find out the problem is solved by adding a PIL to libraries in GAE, and yaml file would solve the issue, since it was complaining about image library in python. the link to all supported libraries for django is https://developers.google.com/appengine/docs/python/tools/libraries27, so add all the needed libraries to .yaml file and to the INSTALL_APP.

django-registration as an APP errors out on __init__.py

I am trying to use django-registration package on my project as an APP. All I did was
Downloaded the package from ""
Copied the "registration" folder under SOWL
In my project's URLs.py added
(r'^accounts/', include('registration.backends.default.urls')),
in my project's settings.py added "registration"
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'CATALOG',
'SOWLAPP',
'registration',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
it gives the following error -
C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 217,
in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", lin
e 105, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 194, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 183, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", l
ine 160, in _fetch
app = import_module(appname)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL\registration\__init__.py", li
ne 3
<!DOCTYPE html>
^
SyntaxError: invalid syntax
C:\SHIYAM\Personal\SuccessOwl\SOWL0.1\SOWL>
I am looking at the urls.py, __init__.py from the registration package and they all look different from the usual urls.py, __init__.py from in the regular apps under my project. Why are they different and what should I do to make it different?
SHM
It looks like something has gone wrong when you were copying the registration app . The traceback suggests that __init__.py contains html like <!DOCTYPE html>, which it definitely shouldn't.

Environment Error when trying to use django-notification app

I am trying to install django-notification app[1] and I get an error when I give manage.py syncdb.
The error states: EnvironmentError: NOTIFICATIONS was not found.
I have installed django-notification using setup tools successfully. This is my stack trace.
File "C:\Tools\Python26\lib\site-packages\django\core\management\__init__.py",
line 438, in execute_manager
utility.execute()
File "C:\Tools\Python26\lib\site-packages\django\core\management\__init__.py",
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 219, in execute
self.validate()
File "C:\Tools\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Tools\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "C:\Tools\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "C:\Tools\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "build\bdist.win32\egg\django_notifications\models.py", line 20, in <module>
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 23, in get_available_backends
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 90, in get_class_instance_by_key
File "build\bdist.win32\egg\django_notifications\backends\xmpp.py", line 33, in __init__
File "build\bdist.win32\egg\django_notifications\backends\__init__.py", line 5
5, in get_settings
EnvironmentError: NOTIFICATIONS was not found.
Any ideas what went wrong?
*Added settings.INSTALLED_APPS part (corrected 'django-notifications' entry to 'notification' as suggested)*
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'filebrowser',
'tinymce',
'south',
'avatar',
'django.contrib.admin',
'notification',
'myproject.main',
)
[1] https://github.com/jtauber/django-notification
For whatever reason, you've decided to add django_notifications to settings.INSTALLED_APPS instead of notification. Fix this.