简体   繁体   English

找不到heroku本地静态

[英]heroku local static not found

'heroku local' can not find static files, but 'python manage.py runserver' finds the static files without issue. 'heroku local'找不到静态文件,但'python manage.py runserver'找到静态文件没有问题。 Can you please help me troubleshoot this issue? 你能帮我解决一下这个问题吗?

settings.py reads: settings.py读取:

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

I run collectstatic and the static files are copied to STATIC_ROOT: 我运行collectstatic,静态文件被复制到STATIC_ROOT:

python manage.py collectstatic

manage.py runserver' finds the static files without issue: manage.py runserver'找到没有问题的静态文件:

python manage.py runserver

While 'heroku local' returns a warning 'not found': 虽然'heroku local'会返回“未找到”警告:

11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/base.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/base.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/login.css
11:52:04 AM web.1 |  [19/May/2016 10:52:04] WARNING [django.request:170] Not Found: /static/admin/css/login.css

Not sure what's happening here. 不知道这里发生了什么。 Both 'heroku local' and 'manage.py runserver' should see the static files. 'heroku local'和'manage.py runserver'都应该看到静态文件。

Note: I am using Django==1.8.2 and settings.py contains: 注意:我使用Django == 1.8.2并且settings.py包含:

import os
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

SECRET_KEY = 'secretkey'

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    # 'django.contrib.sites',
    'django.contrib.admin',
    'registration',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dbbackup',
    'listable',
    'rest_framework',
    'bootstrap3',
    'django_crontab',
)

ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'track.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.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'track.wsgi.application'

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

FIXTURE_DIRS = (
    os.path.join(BASE_DIR, 'fixtures'),
)

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'media/'

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ],
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_xml.parsers.XMLParser',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_xml.renderers.XMLRenderer',
    ),
}

DATABASES = {'default' : dj_database_url.config(default='postgres://testuser:testpw@localhost:5432/testdb')}

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

BOOTSTRAP3 = {
    'include_jquery': True,
}

The solution that works for me (after 24 hours+): 适用于我的解决方案(24小时后+):

1) install the most recent stable version of whitenoise (I was working from an old example, which required whitenoise==2.0.6) 1)安装最新的稳定版本的whitenoise(我正在使用一个旧的例子,需要whitenoise == 2.0.6)

2) make sure you add whitenoise to MIDDLEWARE_CLASSES: 2)确保在MIDDLEWARE_CLASSES中添加了whitenoise:

MIDDLEWARE_CLASSES = (
    'whitenoise.middleware.WhiteNoiseMiddleware',
)

Note: adding 'whitenoise.middleware.WhiteNoiseMiddleware' to the middleware class when using whitenoise==2.0.6 will throw an error. 注意:使用whitenoise == 2.0.6时,将“whitenoise.middleware.WhiteNoiseMiddleware”添加到中间件类将引发错误。 You will need to upgrade to the latest stable version (currently whitenoise==3.1) 您需要升级到最新的稳定版本(目前为whitenoise == 3.1)

I am going to assume these admin files are the ones from the Django admin app. 我将假设这些管理员文件是来自Django管理员应用程序的文件。 Without seeing your project, my best guesses for where you should troubleshoot next are: 在没有看到你的项目的情况下,我最好猜测你接下来要解决的问题是:

1) Check that django.contrib.admin is in your INSTALLED_APPS . 1)检查django.contrib.admin是否在您的INSTALLED_APPS

2) Are you changing the DEFAULT_FILE_STORAGE setting? 2)您是否正在更改DEFAULT_FILE_STORAGE设置? This will interfere with the STATICFILES_FINDERS potentially. 这可能会干扰STATICFILES_FINDERS

3) Check all of the static files settings , if you are overriding any of them, make sure there are no caveats. 3)检查所有静态文件设置 ,如果要覆盖其中任何一个,请确保没有任何警告。

If you post your entire settings.py file, I would have a much better shot at debugging your issue. 如果你发布整个settings.py文件,我会更好地调试你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM