skip to Main Content

I have a telegram bot witch depends on a Django app, I’m trying to deploy it on Heroku but I get this error

django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet.

when it runs python3 main/bot.py in Heroku

here is my Procfile:

web: gunicorn telega.wsgi
worker: python main/bot.py

main/bot.py:

import telebot
import traceback
from decimal import Decimal, ROUND_FLOOR
import requests
import json
from django.conf import settings
from preferences import preferences
from main.markups import *
from main.tools import *

config = preferences.Config
TOKEN = config.bot_token

from main.models import *
from telebot.types import LabeledPrice

# # #
if settings.DEBUG:
    TOKEN = 'mybottoken'
# # #

bot = telebot.TeleBot(TOKEN)

admins = config.admin_list.split('n')
admin_list = list(map(int, admins))


@bot.message_handler(commands=['start'])
def start(message):
    user = get_user(message)
    lang = preferences.Language
    clear_user(user)

    if user.user_id in admin_list:
        bot.send_message(user.user_id,
                        text=clear_text(lang.start_greetings_message),
                        reply_markup=main_admin_markup(),
                        parse_mode='html')
    else:
        bot.send_message(user.user_id,
                        text=clear_text(lang.start_greetings_message),
                        reply_markup=main_menu_markup(),
                        parse_mode='html')


@bot.message_handler(func=lambda message: message.text == preferences.Language.porfolio_button)
def porfolio_button(message):
....
...

and my settings.py:

"""
Django settings for telega project.

Generated by 'django-admin startproject' using Django 2.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import django_heroku
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'sw)pfb7&!l98xdoxn9(hy4eacwm33tj1vknyhz#tmv3mr-@ueo'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['localhost',
                 "https://olk-telegram-bot.herokuapp.com"
                 "olk-telegram-bot.herokuapp.com",
                 "www.olk-telegram-bot.herokuapp.com",
                 "olk-telegram-bot"
                 ".herokuapp.com",
                 ]


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'preferences',
    'main',
    'ckeditor',
    'dbbackup',  # django-dbbackup
]

DBBACKUP_STORAGE = 'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS = {'location': os.path.join(BASE_DIR, "backup")}


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',
]

ROOT_URLCONF = 'telega.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'telega.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'CONN_MAX_AGE': 3600,
        'NAME': 'portfolio',
        'USER': 'mysql',
        'HOST': 'localhost',
        'PORT': '3306',
        'PASSWORD': 'mysql',
        'OPTIONS': {
            'charset': 'utf8mb4',
        },
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

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
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATICFILES_DIRS = [
#     os.path.join(BASE_DIR, "static"),
# ]

CKEDITOR_CONFIGS = {
    'default': {
        'enterMode': 2,
        'linkShowAdvancedTab': False,
        'linkShowTargetTab': False,
        'toolbar': 'Custom',
        'toolbar_Custom': [
            ['Bold', 'Italic', 'Underline'],
            ['Link', 'Unlink'],
            ['RemoveFormat', 'Source']
        ],
    }
}


# Activate Django-Heroku.
django_heroku.settings(locals())

del DATABASES['default']['OPTIONS']['sslmode']

SITE_ID = 2

I don’t know if I’m doing right or no, it’ll be appreciated if you guide me through 🙂

2

Answers


  1. Chosen as BEST ANSWER

    Turns out I should run polling.py not main/bot.py -__-


  2. In settings.py under INSTALLED_APPS you need to do app_name.apps.AppNameConfig.

    So if you app name was telegram_bot you would do telegram_bot.apps.TelegramBotConfig.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search