0
votes

I'm working with django, and trying to deploy my app to heroku.

All is working without any problems in local (even with DEBUG=False), but when deployed to heroku, the admin template doesn't display when DEBUG=False.

I followed theses instructions to configure my settings.py : https://devcenter.heroku.com/articles/django-assets

And here is my Procfile :

web: gunicorn bourse_logements.wsgi -b 0.0.0.0:$PORT

Feel free to ask if yu need some parts of my settings.py, I will paste them

Any help would be appreciated

EDIT : Here is my settings.py : https://gist.github.com/e-goz/62f812ab1fa8f8268f94

3
Could you paste your entire settings.py please? - David Dahan
What exactly do you mean for "template is broken"? Browser return 404? can't open admin page? or just failed to load assets? - Leonardo.Z
@Leonardo.Z : Page is loading, I can login, but the display isn't correct. See : link - egoz

3 Answers

0
votes

Are you sure you didn't .gitignore the templates folder?

0
votes

* Add This line to your setting.py*

ADMIN_MEDIA_PREFIX = '/static/admin/'

you have to also copy all admin CSS and JavaScript to your static path(within static folder) like static/admin/"you staticfiles"

0
votes

You can try This setting as per your configuration on setting.py.

from unipath import Path
PROJECT_DIR = Path(__file__).ancestor(3)
PROJECT_ROOT = Path(__file__).ancestor(2)
sys.path.insert(0, Path(PROJECT_ROOT, 'apps'))
MEDIA_ROOT = PROJECT_DIR.child("media")
MEDIA_URL = '/media/'
STATIC_ROOT = PROJECT_DIR.child("collected_static")
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    PROJECT_DIR.child("static"),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    #'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
TEMPLATE_DIRS = (
    Path(PROJECT_ROOT, 'templates'),
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.flatpages',
)

# Heroku specific settings

import dj_database_url
DATABASES['default'] =  dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# You can also try in your url.py

if settings.LOCAL_DEV:
    baseurlregex = r'^media/(?P<path>.*)$'
    urlpatterns += patterns('',
        (baseurlregex, 'django.views.static.serve',
        {'document_root':  settings.MEDIA_ROOT}),
    )
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()