Deploy python Django project to Heroku. I’m having errors

Asked

Viewed 282 times

0

I’m trying to deploy a Python project using Django on Heroku. deploy is fine, but when trying to make Heroku run python Manage.py migrate the following error occurs.

Traceback (Most recent call last): File "Manage.py", line 23, in execute_from_command_line(sys.argv) File "/app/. Heroku/python/lib/python3.6/site-Packages/Django/core/management/init.py" line 371, in execute_from_command_line Utility.execute() File "/app/. Heroku/python/lib/python3.6/site-Packages/Django/core/management/init.py" line 317, in execute Settings.INSTALLED_APPS File "/app/. Heroku/python/lib/python3.6/site-Packages/Django/conf/init.py" line 56, in getattr self. _setup(name) File "/app/. Heroku/python/lib/python3.6/site-Packages/Django/conf/init.py" line 43, in _setup self. _Wrapped = Settings(settings_module) File "/app/. Heroku/python/lib/python3.6/site-Packages/Django/conf/init.py" line 106, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/app/. Heroku/python/lib/python3.6/importlib/init.py", line 126, in import_module Return _bootstrap. _gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/app/djangosige/configs/init.py", line 3, in from . Settings import * File "/app/djangosige/configs/Settings.py", line 4, in from . configs import DEFAULT_DATABASE_URL, DEFAULT_FROM_EMAIL, EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_PORT, EMAIL_USE_TLS Modulenotfounderror: No module named 'mjsolutions.configs.configs'


This is my configs.py file


# Configuração da base de dados

# Caso seja deixado vazio o default será: 'sqlite:////...djangosige/db.sqlite3'
DEFAULT_DATABASE_URL = 'postgres://meuuser:minhasenhadbc@localhost/nomebd'

# Configurações do servidor de email

# Endereço de email padrão utilizado

DEFAULT_FROM_EMAIL = '[email protected]'

EMAIL_HOST = 'smtp.gmail.com'  # Gmail
# EMAIL_HOST = 'smtp.live.com' #Hotmail

# Usuário do email padrão
EMAIL_HOST_USER = 'meuuser'

# Senha do email padrão
EMAIL_HOST_PASSWORD = 'minhasenha'

#Verificar a port utilizada pelo serviço de email
EMAIL_PORT = 587

EMAIL_USE_TLS = True

My Settings.py

import os
from decouple import config, Csv
from dj_database_url import parse as dburl
from .configs import DEFAULT_DATABASE_URL, DEFAULT_FROM_EMAIL, EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_PORT, EMAIL_USE_TLS

APP_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
PROJECT_ROOT = os.path.abspath(os.path.dirname(APP_ROOT))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=bool)

ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())

if not DEFAULT_DATABASE_URL:
    DEFAULT_DATABASE_URL = 'sqlite:///' + os.path.join(APP_ROOT, 'db.sqlite3')

DATABASES = {
    'default': config('DATABASE_URL', default=DEFAULT_DATABASE_URL, cast=dburl),
}


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

Can anyone help me with this mistake? Thanks in advance

  • there was a comment (as an answer) on my answer in which you affirmed already created the requirements.txt with the pip freeze, ok, but make sure you’re sending that file to Heroku, it needs to be under that name: requirements.txt

1 answer

2

See the end of the error message:

EMAIL_PORT, EMAIL_USE_TLS ModuleNotFoundError: 
      No module named 'mjsolutions.configs.configs'

That is, Voce is calling a module that, although probably installed in its local environment (if it would not work), is not installed in Heroku, to work in Heroku all the packages needed to run in production have to be in the file called requirements.txt, a quick way to make sure you have everything in this file is with the command:

pip freeze > requirements.txt

Care:
If you use the command pip freeze > requirements.txt to generate requirements.txt revise this file at the end, as locally vc may have packages that are not needed by the project, such as debug packages, and especially if you are not isolating environments with some kind of venvs manager. If applicable, remove the unnecessary packets to run on Heroku.

Example of a file requirements.txt:

$ cat requirements.txt 
Django==2.1.5
django-bootstrap4==0.0.7
django-filter==2.0.0
django-tables2==2.0.3
django-markup==1.3
tablib<0.11.99
django-markup[all-filter-dependencies]
djangorestframework==3.9.0
docutils==0.14
docopt==0.6.2
drf-tracking==1.5.0
drfdocs==0.0.11
Markdown==3.0.1
python-dateutil==2.7.5
pytz==2018.9
requests==2.21.0
six==1.12.0
urllib3==1.24.1
whitenoise==4.1.2
yarg==0.1.9
gunicorn

Browser other questions tagged

You are not signed in. Login or sign up in order to post.