Home>

On startuppy manage.py runservereverything works without errors. There was a need to test on the serverheroku... When loaded onherokuarisesApplication error...

Bheroku logsan error:

2021-10-13T07: 44: 14.143374 + 00: 00 heroku [web.1]: Starting process with command `daphne Quiz.asgi: application --port 22236
 --bind 0.0.0.0 -v2`
2021-10-13T07: 44: 16.405529 + 00: 00 app [web.1]: Traceback (most recent call last):
2021-10-13T07: 44: 16.405551 + 00: 00 app [web.1]: File "/app/.heroku/python/bin/daphne", line 8, in <
module >
2021-10-13T07: 44: 16.405640 + 00: 00 app [web.1]: sys.exit (CommandLineInterface.entrypoint ())
2021-10-13T07: 44: 16.405651 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/daphne/cli.py", line
170, in entrypoint
2021-10-13T07: 44: 16.405777 + 00: 00 app [web.1]: cls (). Run (sys.argv [1:])
2021-10-13T07: 44: 16.405779 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/daphne/cli.py", line
232, in run
2021-10-13T07: 44: 16.405911 + 00: 00 app [web.1]: application= import_by_path (args.application)
2021-10-13T07: 44: 16.405911 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/daphne/utils.py", lin
e 12, in import_by_path
2021-10-13T07: 44: 16.405982 + 00: 00 app [web.1]: target= importlib.import_module (module_path)
2021-10-13T07: 44: 16.405992 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, i
n import_module
2021-10-13T07: 44: 16.406091 + 00: 00 app [web.1]: return _bootstrap._gcd_import (name [level:],
 package, level)
2021-10-13T07: 44: 16.406101 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap >
", line 1030, in _gcd_import
2021-10-13T07: 44: 16.406200 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap >
", line 1007, in _find_and_load
2021-10-13T07: 44: 16.406262 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap >
", line 986, in _find_and_load_unlocked
2021-10-13T07: 44: 16.406325 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap >
", line 680, in _load_unlocked
2021-10-13T07: 44: 16.406387 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap_external >
", line 855, in exec_module
2021-10-13T07: 44: 16.406469 + 00: 00 app [web.1]: File "<
frozen importlib._bootstrap >
", line 228, in _call_with_frames_remove
d
2021-10-13T07: 44: 16.406527 + 00: 00 app [web.1]: File "/app/./Quiz/asgi.py", line 9, in <
module >
2021-10-13T07: 44: 16.406642 + 00: 00 app [web.1]: from quiz_app.routing import ws_urlpatterns
2021-10-13T07: 44: 16.406642 + 00: 00 app [web.1]: File "/app/./quiz_app/routing.py", line 3, in <
module >
2021-10-13T07: 44: 16.406724 + 00: 00 app [web.1]: from .consumers import PlayersConsumer
2021-10-13T07: 44: 16.406724 + 00: 00 app [web.1]: File "/app/./quiz_app/consumers.py", line 9, in <
module >
2021-10-13T07: 44: 16.406785 + 00: 00 app [web.1]: from .models import Player, Game
2021-10-13T07: 44: 16.406787 + 00: 00 app [web.1]: File "/app/./quiz_app/models.py", line 5, in <
module >
2021-10-13T07: 44: 16.406853 + 00: 00 app [web.1]: User= get_user_model ()
2021-10-13T07: 44: 16.406863 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/auth/_
_init__.py ", line 160, in get_user_model
2021-10-13T07: 44: 16.406973 + 00: 00 app [web.1]: return django_apps.get_model (settings.AUTH_USER_MODEL, require_ready= False)
2021-10-13T07: 44: 16.406981 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.
py ", line 201, in get_model
2021-10-13T07: 44: 16.407101 + 00: 00 app [web.1]: self.check_apps_ready ()
2021-10-13T07: 44: 16.407109 + 00: 00 app [web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/apps/registry.
py ", line 136, in check_apps_ready
2021-10-13T07: 44: 16.407215 + 00: 00 app [web.1]: raise AppRegistryNotReady ("Apps aren't loaded yet.")
2021-10-13T07: 44: 16.407257 + 00: 00 app [web.1]: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.2021-10-13T07: 44: 16.641612 + 00: 00 heroku [web.1]: Process exited with status 12021-10-13T07: 44: 16.777535 + 00: 00 heroku [web.1]: State changed from starting to crashed
2021-10-13T07: 44: 16.859199 + 00: 00 heroku [web.1]: State changed from crashed to starting
2021-10-13T07: 44: 17.346824 + 00: 00 heroku [router]: at= error code= H10 desc= "App crashed" method= GET path= "/" host= bemaximal
quiz.herokuapp.com request_id= ac617cb3-c39e-4822-a9ac-f5fd589092d1 fwd= "178.125.141.61" dyno= connect= service= status= 5
03 bytes= protocol= http

On startupdjango-admin check:

Traceback (most recent call last):
  File "C: \ Users \ 1 \ AppData \ Local \ Programs \ Python \ Python39 \ lib \ runpy.py", line 197, in _run_module_as_main
    return _run_code (code, main_globals, None,
  File "C: \ Users \ 1 \ AppData \ Local \ Programs \ Python \ Python39 \ lib \ runpy.py", line 87, in _run_code
    exec (code, run_globals)
  File "C: \ Users \ 1 \ PycharmProjects \ Quiz \ venv \ Scripts \ django-admin.exe \ __ main__.py", line 7, in <
module >
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ __ init__.py", line 419, in execute
_from_command_line
    utility.execute ()
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ __ init__.py", line 413, in execute
    self.fetch_command (subcommand) .run_from_argv (self.argv)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ base.py", line 354, in run_from_ar
gv
    self.execute (* args, ** cmd_options)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ base.py", line 398, in execute
    output= self.handle (* args, ** options)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ commands \ check.py", line 63, in ha
ndle
    self.check (
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ management \ base.py", line 419, in check
    all_issues= checks.run_checks (
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ checks \ registry.py", line 76, in run_checks
    new_errors= check (app_configs= app_configs, databases= databases)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ core \ checks \ translation.py", line 60, in check_lan
guage_settings_consistent
    get_supported_language_variant (settings.LANGUAGE_CODE)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ conf \ __ init__.py", line 82, in __getattr__
    self._setup (name)
  File "c: \ users \ 1 \ pycharmprojects \ quiz \ venv \ lib \ site-packages \ django \ conf \ __ init__.py", line 63, in _setup
    raise ImproperlyConfigured (
django.core.exceptions.ImproperlyConfigured: Requested setting LANGUAGE_CODE, but settings are not configured. You must
either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure () before accessing settings.

asgi.py file:

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from quiz_app.routing import ws_urlpatterns
os.environ.setdefault ('DJANGO_SETTINGS_MODULE', 'Quiz.settings')
django.setup ()
application= ProtocolTypeRouter ({
    'http': get_asgi_application (),
    'websocket': AuthMiddlewareStack (
        URLRouter (
            ws_urlpatterns
        )
    ),
})

settings.py file:

"" "
Django settings for Quiz project.
Generated by 'django-admin startproject' using Django 3.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"" "
import os
import dj_database_url
from django.conf import settings
BASE_DIR= os.path.dirname (os.path.dirname (os.path.abspath (__ file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY= '*'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG= True
ALLOWED_HOSTS= ['*']
# Application definition
INSTALLED_APPS= ['django.contrib.admin', 'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_app',
    'quiz_app',
    'channels'
]
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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF= 'Quiz.urls'
TEMPLATES= [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
WSGI_APPLICATION= 'Quiz.wsgi.application'
ASGI_APPLICATION= 'Quiz.asgi.application'
# Database
DATABASES= {
    'default': dj_database_url.config ()
}
prod_db= dj_database_url.config (conn_max_age= 500)
DATABASES ['default']. Update (prod_db)
# Channel_layers
CHANNEL_LAYERS= {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [os.environ.get ('REDIS_URL', 'redis: //localhost: 6379')],
        },
    },
}
# Password validation
AUTH_PASSWORD_VALIDATORS= [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]
# Internationalization
LANGUAGE_CODE= 'en-us'
TIME_ZONE= 'UTC'
USE_I18N= True
USE_L10N= True
USE_TZ= True
# Static files (CSS, JavaScript, Images)
STATIC_URL= '/static /'
STATIC_ROOT= os.path.join (BASE_DIR, 'staticfiles')
STATICFILES_DIRS= [os.path.join (BASE_DIR, 'static')]
MEDIA_URL= '/media /'
MEDIA_ROOT= os.path.join (BASE_DIR, 'media')
STATICFILES_STORAGE= 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Default primary key field type
DEFAULT_AUTO_FIELD= 'django.db.models.BigAutoField'

Project structure:

Thank you)

Is this the full text of the error?

andreymal2021-10-14 04:03:11

I have updated the error text, now complete ...

matrixoidr2021-10-13 07:46:50

The error text hints that you forgot to set the DJANGO_SETTINGS_MODULE environment variable newbedev.com/...

andreymal2021-10-13 09:11:59

However, when calling heroku config in the field DJANGO_SETTINGS_MODULE: Quiz.settings

matrixoidr2021-10-13 09:18:27