0
问我的问题之前,我的理解是有同一个问题一个高度评价的问题:Apache not serving django admin static files阿帕奇不服务管理静态文件Django的
不过,我已经试过了同样的解决方案可以看出以下 这是我的Apache的conf文件:
WSGIScriptAlias//home/ubuntu/sportsgullyrest/SportsGullyRest/wsgi.py
WSGIPythonPath /home/ubuntu/sportsgullyrest/venv/bin/python2.7
Alias /static/admin /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin
Alias /static/ /home/ubuntu/sportsgullyrest/static/
<Directory /home/ubuntu/sportsgullyrest/SportsGullyRest>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
<Directory /home/ubuntu/sportsgullyrest/static>
Require all granted
</Directory>
<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
我使用Django 1.7,这里是我的设置文件
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
TEMPLATE_PATH = os.path.join(PROJECT_PATH, 'templates')
STATIC_PATH = os.path.join(PROJECT_PATH, 'static')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '...'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
...
)
MIDDLEWARE_CLASSES = (
...
)
AUTHENTICATION_BACKENDS = (
...
)
TEMPLATE_CONTEXT_PROCESSORS = (
...
)
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
...
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = None
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = 'static/'
MEDIA_URL = '/static/img/'
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
STATICFILES_DIRS = (
STATIC_PATH,
)
我只面临一个更多的错误。这似乎是我的主要静态文件没有收集使用'collectstatic'。所以现在Django静态文件被提供,但是我的前端静态资源没有找到,因为它们不存在于新创建的staticfiles文件夹中 – Newtt
因此,您的STATICFILES_DIRS确实需要包含您称为STATIC_PATH的内容,之前我错了(我被简单地弄糊涂了,因为你已经定义了,而不是STATIC_ROOT:_PATH不是标准的Django设置)。 –