Heroku and DJango_Filters

96 views
Skip to first unread message

Charlotte Wood

unread,
Jun 26, 2019, 11:59:39 AM6/26/19
to django...@googlegroups.com
I need help.

I've followed the directions to a "T."  

1.  My site works PERFECTLY on my local host in my virtual environment.  NO errors, migrates fine, runs fine and looks beautiful.

2.  BEFORE I added Django-filters to my pages, it worked GREAT on Heroku.

3.  AS SOON as I put the DJango_filters in it, BOOM, Heroku won't run it.  I can find literally no documentation except for the textbook info from DJango, which doesn't troubleshoot at all.

Has anyone had this trouble already?

I have to get this up and running!

ANY suggestions would be helpful.  ANY.....

Fabio C. Barrionuevo da Luz

unread,
Jun 26, 2019, 12:12:30 PM6/26/19
to django...@googlegroups.com
Is very hard to help you without the full traceback of the errors.
run:

heroku logs

put the output into https://gist.github.com/

and send the generated link.

ps: make sure you remove from the traceback any line related to password, api keys 

Many years ago, they recommended me to read this text here http://www.catb.org/esr/faqs/smart-questions.html.
(although it does not agree with some parts of it, it gives you an idea of how to elaborate questions to make it easier for volunteers to help you)




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPZR0N4O0MorKsihVqZzbNmsrkptZgo2tqy_NfGUi%2BnF0_mZ6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Fábio C. Barrionuevo da Luz
Palmas - Tocantins - Brasil - América do Sul


Blog colaborativo sobre Python e tecnologias Relacionadas, mantido totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e mandar o pull-request. Leia mais sobre como publicar em README.md e contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python ou é útil para quem usa Python? Está esperando o que? Publica logo, que estou louco para ler...

Sithembewena L. Dube

unread,
Jun 26, 2019, 12:13:41 PM6/26/19
to django...@googlegroups.com
Hi Charlotte,

What sort of error do you see?

Also, have your checked your logs on Heroku?

Lastly, if you have a sandbox on Heroku, you could run the site there in debug mode to get more specific error information.

Kind regards,
Lloyd


Sent with Shift

--

Charlotte Wood

unread,
Jun 26, 2019, 12:56:37 PM6/26/19
to django...@googlegroups.com
The only error I keep seeing is "No Module Found" for django-filters

But, I don't understand why it runs perfectly on my local host, every single page, then heroku just hates django filters.  I was hoping someone else had the same issues and remembered.  But, I will follow up with the error logs in a sec.  Thanks ya'll!!

Sithembewena L. Dube

unread,
Jun 26, 2019, 1:07:45 PM6/26/19
to django...@googlegroups.com
It sounds like the package django-filters is not installed on your Heroku environment.

Do you have a dependency file suck as a Pipfile or requirements.txt? If you do, you will need to install all dependencies listed there on your Heroku server (at least those you need for production use).


Kind regards,
Lloyd


Sent with Shift

Sithembewena L. Dube

unread,
Jun 26, 2019, 1:08:10 PM6/26/19
to django...@googlegroups.com
Oops - I meant 'such as'.


Kind regards,
Lloyd


Sent with Shift

SOUMAHORO Moussa

unread,
Jun 26, 2019, 2:39:23 PM6/26/19
to django...@googlegroups.com
Hi Charlotte,
If you are using a versionning manager like git, you can create another branch from the branch that contains the bug and reset the bug branch to one of your commit which is good  and 
go step by step to avoid the error that you got.


Arahmat Ayoub

unread,
Jun 26, 2019, 2:39:36 PM6/26/19
to django...@googlegroups.com
Hi Charlotte ,
i 'd happy to help with your issue



Mailtrack Sender notified by
Mailtrack 06/26/19, 06:10:23 PM

--

Charlotte Wood

unread,
Jun 26, 2019, 3:07:32 PM6/26/19
to django...@googlegroups.com
ok, stupid question....

is there a heroku pip install?

all of my dependencies are installed and listed on my requirements.txt file just like they're supposed to be.

do i pip install somewhere OTHER than my folder in my virtual environment?

i could be totally crazy, but i don't remember every using heroku pip install.....

Charlotte Wood

unread,
Jun 26, 2019, 3:08:34 PM6/26/19
to django...@googlegroups.com
I am currently uninstalling and re-installing everylthing, but I would love for you to help with this issue.  

Fabio C. Barrionuevo da Luz

unread,
Jun 26, 2019, 3:17:40 PM6/26/19
to django...@googlegroups.com
Heroku use a "buildpack"  https://devcenter.heroku.com/articles/buildpacks to do automate some things in the deployment.
you can attach one or more buildpacks to your project in heroku
you can also create your own buildpack to customize it.

specifically for Python, the heroku python buildpack (https://github.com/heroku/heroku-buildpack-python) will:

- search a "requirements.txt" file on root directory and install all packages listed on that file.
- search pipenv related files and install all packages listed on that file.

in short, have a requirements.txt file in your root directory






For more options, visit https://groups.google.com/d/optout.


--

Sithembewena L. Dube

unread,
Jun 26, 2019, 3:22:18 PM6/26/19
to django...@googlegroups.com
It's not stupid to ask :)

You could run the "pip freeze" command and then see what pip on Heroku says it has.

Also, perhaps your virtual environment's site packages directory on Heroku is not on the Python path. I have had such a challenge on WebFaction, but having never used Heroku I wouldn't want to give you incorrect tips to solve it.

You can find out what's on your path by running the command "echo $PATH" without quotes and see if your virtual environment's path is in the PATH variable.


Kind regards,
Lloyd


Sent with Shift

Charlotte Wood

unread,
Jun 26, 2019, 3:22:19 PM6/26/19
to django...@googlegroups.com
I have that.  That's not the problem.  My specific problem is django_filters.  My app worked totally fine until I added these filters.  My questions was:  has anyone had trouble with django-filters and if so, how did you fix it?

Fabio C. Barrionuevo da Luz

unread,
Jun 26, 2019, 3:26:43 PM6/26/19
to django...@googlegroups.com
make sure that you use the right package in your requirements.txt

This is the package that everyone uses:

django-filter 
https://pypi.org/project/django-filter/

This is another package with a very similar name

https://pypi.org/project/django-filters/




For more options, visit https://groups.google.com/d/optout.

Sithembewena L. Dube

unread,
Jun 26, 2019, 3:29:02 PM6/26/19
to django...@googlegroups.com
Charlotte, is django-filters listed in your settings file on Heroku as below?

INSTALLED_APPS = [
    ...
    'django_filters',
]

Kind regards,
Lloyd


Sent with Shift

Sithembewena L. Dube

unread,
Jun 26, 2019, 3:30:01 PM6/26/19
to django...@googlegroups.com

Charlotte Wood

unread,
Jun 26, 2019, 6:58:43 PM6/26/19
to django...@googlegroups.com
Thanks everyone....so I've unistalled and reinstalled everything and same errors.  I so much appreciate ANY help:

settings.py file reads like this:


import os
import django_heroku
from decouple import config
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = config('SECRET_KEY')

DEBUG = True

ALLOWED_HOSTS = []

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'freshstart.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 = 'freshstart.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
    }
}

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


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

django_heroku.settings(locals())




REQUIREMENTS.TXT FILE:

j-database-url==0.5.0
Django==2.2
django-filter==2.1.0
django-heroku==0.3.1
gunicorn==19.9.0
psycopg2==2.8.3
python-decouple==3.1
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2

I have a Procfile and a Pipfile.  The Procfile was put there using touch . Procfile in Git Bash.

When I try to push to Heroku, now I get this error for django_heroku, but you can see, it's plainly installed and imported at the top of my settings file.

Should I complete uninstall and re-install Python?


Here is my error:

Enumerating objects: 80, done.
Counting objects: 100% (80/80), done.
Delta compression using up to 4 threads
Compressing objects: 100% (76/76), done.
Writing objects: 100% (80/80), 38.18 KiB | 566.00 KiB/s, done.
Total 80 (delta 16), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.7.3
remote: -----> Installing pip
remote: -----> Installing dependencies with Pipenv 2018.5.18…
remote:        Installing dependencies from Pipfile.lock (7fdd58)…
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 204, in fetch_command
remote:            app_name = commands[subcommand]
remote:        KeyError: 'collectstatic'
remote:        During handling of the above exception, another exception occurred:
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 21, in <module>
remote:            main()
remote:          File "manage.py", line 17, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
remote:            settings.INSTALLED_APPS
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 79, in __getattr__
remote:            self._setup(name)
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 66, in _setup
remote:            self._wrapped = Settings(settings_module)
remote:          File "/app/.heroku/python/lib/python3.7/site-packages/django/conf/__init__.py", line 157, in __init__
remote:            mod = importlib.import_module(self.SETTINGS_MODULE)
remote:          File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module

remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 983, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
remote:          File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
remote:          File "<frozen importlib._bootstrap_external>", line 728, in exec_module
remote:          File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
remote:          File "/tmp/build_c255721dd1d2732fd6d23e4f7726e08a/freshstart/settings.py", line 6, in <module>
remote:            import django_heroku
remote:        ModuleNotFoundError: No module named 'django_heroku'
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:

remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to epiclivetest2.
remote:
To https://git.heroku.com/epiclivetest2.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/epiclivetest2.git'

Sithembewena L. Dube

unread,
Jun 26, 2019, 7:09:42 PM6/26/19
to django...@googlegroups.com
Hi Charlotte,

I spotted the problem.

You need to add 'django-filters' to your settings.py file.

Like so:


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'maintenance',
  'django-filters',
]

Then run python manage.py migrate (if the app needs a database schema, the command will generate it.


Try this?


Kind regards,
Lloyd

Sithembewena L. Dube

unread,
Jun 26, 2019, 7:09:42 PM6/26/19
to django...@googlegroups.com
Charlotte, I am now typing from my phone (away from my desk) but if you still need help after trying out my last recommendation, I would be happy to look at it for you.


Kind regards,
Lloyd

--

Charlotte Wood

unread,
Jun 26, 2019, 7:59:13 PM6/26/19
to django...@googlegroups.com
yes, but look at the error...now it isn't recognize the django-heroku app all of a sudden.  it's not yielding any error on django_filters.....  you think my python is corrupt?

Charlotte Wood

unread,
Jun 26, 2019, 7:59:31 PM6/26/19
to django...@googlegroups.com
remote:          File "/tmp/build_c255721dd1d2732fd6d23e4f7726e08a/freshstart/settings.py", line 6, in <module>
remote:            import django_heroku
remote:        ModuleNotFoundError: No module named 'django_heroku'  

Sithembewena L. Dube

unread,
Jun 27, 2019, 5:20:01 AM6/27/19
to django...@googlegroups.com
It would be helpful to do a clean setup and then view the log files.


Kind regards,
Lloyd

Reply all
Reply to author
Forward
0 new messages