所以我将我的代码推送到Heroku,我在使用工作方面遇到了很多麻烦。静态文件不起作用,我安装了WhiteNoise等,但是一旦我使用{%static 'js/whatever.js'%}
我就破坏了网站,但可以在不破坏服务器的情况下使用{% load staticfiles %}
。目前我的理论是管理员不会因为静态文件而加载,但正常的django管理员不需要它们吗?
以下是我的重要观点,我希望有人发现错误。 settings.py
DEBUG = False
ALLOWED_HOSTS = [u'....herokuapp.com']
import dj_database_url
DATABASES ={'default':dj_database_url.parse('postgres://...jl4',conn_max_age=600)}
INSTALLED_APPS = [
'rest_framework',"rest_framework.authtoken",'django.contrib.admin','django.contrib.auth','django.contrib.staticfiles',]
AUTHENTICATION_BACKENDS =('django.contrib.auth.backends.ModelBackend',)
SITE_ID = 1
WSGI_APPLICATION = 'ABC.wsgi.application'
STATIC_URL = '/static/'
STATICFILES_DIRS =[os.path.join(BASE_DIR, 'static'), ]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
STATICFILES_STORAGE ='whitenoise.django.GzipManifestStaticFilesStorage'
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ABC.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
application.add_files('/ABC/static/', prefix='/static/')
Procfile文件,requirements.txt,.git文件夹存在且看起来正常。我在127.0.0.1上没有任何问题。任何地方都没有迁移问Heroku配置了Python Buildpack和Postgres。 404 500等处理程序已安装并正常工作(顺便说一下,我得到500内部服务器错误)。
当我用DEBUG=True
在线推送代码时(我知道你不应该这样做,但我完全感到沮丧),我完全没有问题。可以访问管理员并可以加载静态文件而不会出现任何问题。
所以,如果有人有想法丢失,请告诉我。没有愚蠢的评论/问题我需要答案!
from django.contrib import admin
from django.conf.urls import (
handler400, handler403, handler404, handler500
)
handler400 = 'my_profile.views.server_error'
handler403 = 'my_profile.views.server_error2'
handler404 = 'my_profile.views.server_error3'
handler500 = 'my_profile.views.server_error4'
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^my_profile/',include('my_profile.urls',namespace='my_profile')),
url(r'^login/',include('login.urls')),
url(r'^logout/',include('login.urls')),
url(r'^register/', include('registration.backends.simple.urls')),
url(r'^userprofile/',include('userprofile.urls')),
url(r'^about/',include('about.urls')),
url('^inbox/notifications/',include(notifications.urls,namespace='notifications')),