0
私はdjangoアプリケーション(1.7)を継承しており、Apache2にインストールすることになっています。コマンドプロンプトからrunserverを実行すると、すべてがうまく動作しますが、apache2/mod_wsgiにデプロイされます。django静的フォルダはapache2で提供されません
私はSTATICFILES_DIRSが正しく設定されていることを確信しています。
settings.pyは、以下のようなものです:
"""
Django settings for sampleapp project.
Generated by 'django-admin startproject' using Django 1.10.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'tf07wvjy+#g&&#s$spi34_c-jno^8_cb0bw=*dx2ni2+w6x-(h'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# ALLOWED_HOSTS = ['0.0.0.0', 'localhost']
ALLOWED_HOSTS = ['192.168.1.36', 'localhost']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 'south',
'CordeliaHanelBackend',
'tastypie',
'StudioHanel',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'CordeliaHanelBackend.urls'
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
# TEMPLATE_DIRS = (
# '/var/www/CordeliaHanelBackend-master/StudioHanel/templates/StudioHanel',
#)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/var/www/CordeliaHanelBackend-master/StudioHanel/templates/StudioHanel','CordeliaHanelBackend/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 = 'CordeliaHanelBackend.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/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.10/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
# os.path.join(BASE_DIR, "static"),
'/var/www/CordeliaHanelFrontend-master/www/dist/',
# '/var/www/CordeliaHanelFrontend-master/www/app',
# '/var/www/CordeliaHanelBackend-master/StudioHanel/static',
)
# STATIC_ROOT = '/var/www/CordeliaHanelFrontend-master/www/app'
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
# DEFAULT_FILE_STORAGE = '/var/www/CordeliaHanelFrontend-master/www/app'
SOUTH_DATABASE_ADAPTER = {
'default': 'south.db.sqlite3'
}
、ここでは、apache2の設定サイトで入手可能なファイルです。あなたがApacheの設定でプロジェクトへのパスを定義する必要が
<VirtualHost *:80>
WSGIDaemonProcess sampleapp python-path=/var/www/CordeliaHanelBackend-master:/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias//var/www/CordeliaHanelBackend-master/CordeliaHanelBackend/wsgi.py
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# EDIT
Alias /static /var/www/CordeliaHanelFrontend-master/www/dist/
<Directory /var/www/CordeliaHanelFrontend-master/www/dist/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
だからここで静的URLで静的ファイルを処理することApacheの設定で行がありますか?なぜDjangoの設定でSTATIC_ROOTの定義をコメントアウトしたのですか? –
Ok上記の編集を行い、Alias/static/var/www/CordeliaHanelFrontend-master/www/dist/ を追加しました。 オーダー可、拒否 許可すべて –
STATIC_ROOTについては、私はその役割を理解していません。私はそれがデバッグモードでのみ有用であることを尋ねた。だから、私は生産のためだけに設定ファイルは、静的ファイルを提供するための十分だと言うだろう。正しい? –