2014-02-19 27 views
1

我在Django 1.5中有一個項目並在Heroku上託管它。 問題是,我沒有看到服務器靜態文件(CSS,JS)(在用戶和管理員) - 通過教程可用在:https://devcenter.heroku.com/articles/django-assets 但沒有什麼幫助。django 1.5中的靜態文件 - 在本地工作,而不是在Heroku上工作

當我使用python manage.py runserver在本地啓動應用程序時 - 一切正常。下面是從文件setting.py

import dj_database_url 

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

    # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
    import os 
    BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 


    # Quick-start development settings - unsuitable for production 
    # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ 

    # SECURITY WARNING: don't run with debug turned on in production! 
    DEBUG = False 

    TEMPLATE_DEBUG = True 

    ALLOWED_HOSTS = ['*'] 


    # Application definition 

    INSTALLED_APPS = (
     'django.contrib.admin', 
     'django.contrib.auth', 
     'django.contrib.contenttypes', 
     'django.contrib.sessions', 
     'django.contrib.messages', 
     'django.contrib.staticfiles', 
     'app', 
    ) 

    MIDDLEWARE_CLASSES = (
     '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 = 'blog_project.urls' 

    WSGI_APPLICATION = 'blog_project.wsgi.application' 


    # Database 
    # https://docs.djangoproject.com/en/1.6/ref/settings/#databases 

    DATABASES = {'default': dj_database_url.config()} 


    # Internationalization 
    # https://docs.djangoproject.com/en/1.6/topics/i18n/ 

    LANGUAGE_CODE = 'en-us' 

    TIME_ZONE = 'UTC' 

    USE_I18N = True 

    USE_L10N = True 

    USE_TZ = True 


    # Static files (CSS, JavaScript, Images) 
    # https://docs.djangoproject.com/en/1.6/howto/static-files/ 

    STATIC_URL = '/static/' 
    STATIC_ROOT = 'staticfiles' 

    STATICFILES_DIRS = (
     os.path.join(BASE_DIR, 'static'), 
    ) 

回答

0

我想你需要更改設置了Heroku的,讓你有

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) 
STATICFILES_DIRS = (
    os.path.join(PROJECT_PATH, 'static'), 
)  

它使用不同的查找到

BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 
+0

代碼這解決了這個問題:從dj_static導入Cling application = Cling(get_wsgi_application()) 謝謝 – Mariusz

相關問題