简体   繁体   中英

Django heroku internal server error after deploying

I have deployed my django app to heroku and I am getting Internal Server Error in the website.

settings.py:

'ALLOWED_HOSTS = ['http://127.0.0.1:8000/','https://stripetestdjango.herokuapp.com/', 'localhost']

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',

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


MEDIA_URL = '/images/'


STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

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


MEDIA_ROOT = BASE_DIR / 'static/images'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

STATICFILES_STORAGE =  'django.contrib.staticfiles.storage.StaticFilesStorage' 



if os.getcwd() == '/app':
    DEBUG = False

The heroku log shows the below:

在此处输入图像描述

I have.env file. How to push that to server as well as I am deploying using heroku. I guess the error is it is not able to find my.env file.

Please feel free to ask for more details if needed.

You should never push an .env file containing sensitive data (ie SECRET_KEY_STRIPE) but rather use Heroku Config Vars .

You can fetch the env variable using Python os , while on your local development environment it is a good idea to keep the .env with the value you need for developing/testing.

def get_mysecret():
  return os.environ.get("MY_SECRET", "")

See screenshot (you can use create the Config Var with the command line if you prefer): 创建 Heroku ConfigVar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM