簡體   English   中英

Apache不為Django提供管理靜態文件

[英]Apache not serving admin static files for django

在問我的問題之前,我了解關於同一問題有一個高度評價的問題: Apache不提供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,
)

您必須定義STATIC_ROOT設置,例如os.path.join(BASE_PATH, 'staticfiles')

然后,從Apache conf中刪除/static/admin/別名,確保static別名指向staticfiles目錄,然后運行./manage.py collectstatic

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM