我有一個django(1.8)項目,我在python 3中使用Apache2.4和libapache2-mod-wsgi-py3。而且一切工作到目前爲止,但我的靜態文件沒有通過。以前,當我在Windows環境中嘗試這個,它一切正常。請幫忙。設置完static_root和所有模板後,我運行了'manage.py collectstatic'。 以下是relavent代碼: Settings.pyapache2沒有爲我的django 1.8開發和生產中的靜態文件提供
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'kombu.transport.django',
'myapp',
)
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 = 'primer_suite.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 = 'primer_suite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static_in_pro", "static_root") #where static files are collected
#"/var/www/example.com/static/" #whats served when we go live,
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static_in_pro", "our_static"), #static project for the file
#'/var/www/static/',
)
#files in STATIC_DIRS will be synced to STATIC_ROOT when 'collectstatic' is run.
#folder info
#static_in_pro - statics for our project is
#static root - where static files for the project are collected
MEDIA_URL= '/media/'
MEDIA_ROOT= os.path.join(BASE_DIR, "static_in_pro", "media_root")
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/myprojects/path/to/my/project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "primer_suite.settings")
application = get_wsgi_application()
myproject.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin [email protected]
ServerName myweb.com
ServerAlias www.myweb.com
DocumentRoot /var/www/path/to/my/project
Alias /static/ /var/www/myprojects/path/to/my/project/static-only/static_root
<Directory /var/www/myprojects/path/to/my/project/static-only/static_root>
Require all granted
</Directory>
Alias /templates/ /var/www/myprojects/primer_suite/templates/
<Directory /var/www/myprojects/path/to/my/project/template>
Require all granted
</Directory>
Alias /media/ /var/www/myprojects/path/to/my/project/media/
<Directory /var/www/myprojects/path/to/my/project/media>
Require all granted
</Directory>
WSGIDaemonProcess primer_suite python-path=/var/www/myprojects:/var/www/myprojects/env/lib/python3.4/site-packages
WSGIProcessGroup primer_suite
WSGIScriptAlias//var/www/myprojects//path/to/my/project/my_project/wsgi.py
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我不知道是什麼正在進行。其他一切都很完美。任何幫助將不勝感激。
感謝
感謝您的幫助。非常感激。我一直在看代碼這麼久。我沒有看到這一點。 –