Server error (500) Django deployment on heroku

后端 未结 2 521
执念已碎
执念已碎 2020-12-18 15:33

I turned debug to False in my settings.py file (note that before I turned it to false, everything was workign perfectly) and when I ran git push heroku master a

相关标签:
2条回答
  • 2020-12-18 16:06

    I had the same error.

    I solved issue by removing import django heroku in settings.py

    0 讨论(0)
  • 2020-12-18 16:24

    I had a similar problem and it's hard to figure out when DEBUG is set to False. When I reconfigured it back to DEBUG = True everything worked fine again. So the problem was

    You don't generally see this error in development because when DEBUG = True, ManifestStaticFilesStorage switches to non-hashed urls. https://stackoverflow.com/a/51060143/7986808

    The solution to the problem in your case may differ from mine. But you can find the problem by changing the logging method of your Django project, so you can see more info in the command line when running heroku logs -t -a <heroku-app> even in DEBUG = False mode.

    Change your django logging settings in settings.py as follow:

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': ('%(asctime)s [%(process)d] [%(levelname)s] '
                           'pathname=%(pathname)s lineno=%(lineno)s '
                           'funcname=%(funcName)s %(message)s'),
                'datefmt': '%Y-%m-%d %H:%M:%S'
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            }
        },
        'handlers': {
            'null': {
                'level': 'DEBUG',
                'class': 'logging.NullHandler',
            },
            'console': {
                'level': 'INFO',
                'class': 'logging.StreamHandler',
                'formatter': 'verbose'
            }
        },
        'loggers': {
            'django': {
                'handlers': ['console'],
                'level': 'DEBUG',
                'propagate': True,
            },
            'django.request': {
                'handlers': ['console'],
                'level': 'DEBUG',
                'propagate': False,
            },
        }
    }
    

    Then run heroku logs -t -a <heroku-app> and open the url where you previously got 500 Error you will find out the problem in logs. Hope this will help you.


    In case there are some static files missing just switch your static root in settings.py as follow STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles'). Running heroku run python manage.py collectstatic -a <heroku-app> creates staticfiles directory.

    0 讨论(0)
提交回复
热议问题