我正在使用django,并尝试将我的应用部署到heroku。
All在本地工作没有任何问题(即使使用DEBUG = False),但是当部署到heroku时,DEBUG = False时不会显示管理模板。
我按照这些说明配置了我的settings.py: https://devcenter.heroku.com/articles/django-assets
这是我的Procfile:
web: gunicorn bourse_logements.wsgi -b 0.0.0.0:$PORT
随意询问你是否需要我的settings.py的某些部分,我会粘贴它们
任何帮助将不胜感激
编辑: 这是我的settings.py: https://gist.github.com/e-goz/62f812ab1fa8f8268f94
答案 0 :(得分:0)
*将此行添加到您的setting.py *
ADMIN_MEDIA_PREFIX = '/static/admin/'
您还必须将所有管理CSS和JavaScript复制到静态路径(在静态文件夹中) 比如static / admin /“you staticfiles”
答案 1 :(得分:0)
您可以按照setup.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特定设置
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 = ['*']
#您也可以尝试使用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()
答案 2 :(得分:0)
你确定你没有.gitignore模板文件夹吗?