Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Apache不为django提供管理静态文件_Python_Django_Apache_Mod Wsgi - Fatal编程技术网

Python Apache不为django提供管理静态文件

Python Apache不为django提供管理静态文件,python,django,apache,mod-wsgi,Python,Django,Apache,Mod Wsgi,在问我的问题之前,我知道关于同一个问题有一个被高度评价的问题: 但是,我尝试了与下面相同的解决方案 这是我的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/d

在问我的问题之前,我知道关于同一个问题有一个被高度评价的问题:

但是,我尝试了与下面相同的解决方案 这是我的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>

您必须定义一个静态根设置,类似于
os.path.join(基本路径,'staticfiles')


然后,从Apache配置中删除
/static/admin/
别名,确保
static
别名指向staticfiles目录,然后运行
/manage.py collectstatic

我只面临一个错误。似乎我的主要静态文件没有使用
collectstatic
收集。现在Django静态文件已经提供了,但是我的前端静态资产没有找到,因为它们不存在于新创建的staticfiles文件夹中。因此,您的staticfiles\u目录确实需要包含您称之为static\u路径的内容,我以前在这方面是错的(我有点困惑,因为您定义了它而不是静态的_根:_pathone不是标准的Django设置)。
# 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,
)