Server Error (500) on Heroku using Django

Asked

Viewed 914 times

0

When I try to access my website hosted on Heroku, it returns the message: "Server Error (500)".

Heroku[router]: at=info method=GET path="/favicon.ico" host=quiz-py.herokuapp.com request_id=ef039cdc-8d6a-4735-9a91-942d546c5d06 Fwd="170.79.165.63" Dyno=web.1 connect=1ms service=25ms status=500 bytes=366 Protocol=https

Settings:

DEBUG = False
ALLOWED_HOSTS = ["https://quiz-py.herokuapp.com/", "127.0.0.1"]
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
django_heroku.settings(locals())

wsgi py.:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

#application = get_wsgi_application()

from dj_static import Cling
application = Cling(get_wsgi_application())

Procfile:

web: gunicorn app.wsgi --log-file -

I don’t know why, I did a lot of research but I couldn’t find an answer.

2 answers

1

So, I had the same problem and I was able to solve it in the following way:

I added the following line to the file py Settings.:

DISABLE_COLLECTSTATIC=1

Then I created a folder on the project root with the name 'Static' and copied the static files for her.

(I haven’t moved, but maybe it works if you move too).

Ah, then I migrated the model, with the command:

Heroku run python Manage.py migrate

Then I deployed again, using the git commands and it worked normally.

P.S.: Local database data (sqlite3) does not go up together with the project.

There must be a way to upload such data, but I haven’t yet researched.

0

Dude, with me was giving the same error (500), and in my case the problem was with the static files in html code that I referenced wrong.

The way I made and was making a mistake:

<link rel="stylesheet" href="{% static '../static/css/login.css' %}">

Referencing of the form correct:

<link rel="stylesheet" href="{% static 'css/login.css' %}">

This serves not only to import the css but to the other static files (images and Javascript)

py Settings.:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATICFILES_DIRS = [
    BASE_DIR / "static",
]

STATIC_ROOT = BASE_DIR / "staticfiles"

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

I hope I helped someone !!

Browser other questions tagged

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