2017-02-22 4 views
0

Ich weiß, es gibt ähnliche Fragen, aber glaube mir, ich habe jede von ihnen durchlaufen, aber immer noch nicht meine statischen Dateien durchlaufen. Jede Hilfe wird sehr geschätzt.Heroku nicht gefunden statische Dateien Django

Ich habe alle meine Einstellungen und andere Codes unten.

Die Erfassung unten zeigt, wenn ich
$ Heroku laufen Python manage.py collectstatic
und die erorr ich laufen, wenn ich meine Anwendung bereitstellen.

Capture

setting.py:

import os 
import dj_database_url 

# this is because I have my setting.py under setting folder 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 

SECRET_KEY = os.environ['secret_key'] 

DEBUG = False 

ADMINS = [] 
ALLOWED_HOSTS = ['*'] 

EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD'] 
EMAIL_PORT = 587 
EMAIL_USE_TLS = True 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.sites', 
    'registration', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    # third party apps 
    'crispy_forms', 
    # my apps 
    'home', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    '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', 
] 

ROOT_URLCONF = 'site2.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'templates')], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.template.context_processors.i18n', 
       'django.template.context_processors.media', 
       'django.template.context_processors.static', 
       'django.template.context_processors.tz', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'site2.wsgi.application' 


DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 

db_from_env = dj_database_url.config() 
DATABASES['default'].update(db_from_env) 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


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


STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 

# registration settings 
ACCOUNT_ACTIVATION_DAYS = 7 
REGISTRATION_AUTO_LOGIN = True 
SITE_ID = 1 
LOGIN_REDIRECT_URL = '/' 

# crispy form settings 
CRISPY_TEMPLATE_PACK = 'bootstrap3' 

procfile:

web: gunicorn site2.wsgi --log-file - 

wsgi.py:

import os 

from django.core.wsgi import get_wsgi_application 
from whitenoise.django import DjangoWhiteNoise 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site2.settings") 

application = get_wsgi_application() 
application = DjangoWhiteNoise(application) 

urls.py:

from django.conf.urls import url, include 
from django.contrib import admin 
from django.conf import settings 
from django.conf.urls.static import static 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^accounts/', include('registration.backends.default.urls')), 
    url(r'^', include('home.urls')), 
] 

if not settings.DEBUG: 
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 

Hier ist ein Teil meiner Vorlage, die nicht richtig geladen wird:

<!DOCTYPE html> 
{% load static from staticfiles %} 
<html lang="en"> 
    <head> 

    <!-- Custom styles for this template --> 
    <link href="{% static 'css/offcanvas.css' %}" rel="stylesheet"> 
</head> 
+0

versuchen {% laden statisch%} anstelle von {% laden statisch von staticfiles%} – Darshan

+0

Nicht erfolgreich! – Majid

Antwort

0

Änderung urls.py:

if settings.DEBUG is True: 
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 

Oder entfernen statische Code in Urls dient, weil whitenose dient statische Dateien, müssen Sie keine statischen Dateien von Django in Heroku liefern.

+0

Funktioniert immer noch nicht! Ich habe statische Serving-Code in URL auskommentiert und pushedhephtin wieder zu Heroku, ich sehe es statische Dateien verarbeitet, wenn ich $ heroku ausführen python manage.py collectstatic [Nachbearbeitete 'js/googlemap.js' als 'js/googlemap.fbc11c53299d .js '], aber immer noch kann .js oder .css in meiner App nicht gefunden werden – Majid

+0

Bitte ändern Sie 'STATICFILES_DIRS = [os.path.join (BASE_DIR,' statisch ')]' zu 'STATICFILES_DIRS = [os.path.join (BASE_DIR, 'statisch'),] ' – ruddra

+0

Nein! Funktioniert immer noch nicht! – Majid

Verwandte Themen