2017-04-25 18 views
1

我使用Django CMS製作了一個簡單的網站。除了管理工具欄上的樣式以外,一切似乎都奏效。他們沒有加載。我應該怎麼做才能配置應用程序或服務器以正確地提供服務?在Apache中使用Django CMS管理方式進行生產

這裏是settings.py

import os 

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.8/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = 'some secret here' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'djangocms_admin_style', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.sites', 
    'cms', 
    'menus', 
    'treebeard', 
    'sekizai', 
    'filer', 
    'easy_thumbnails', 
    'mptt', 
    'djangocms_text_ckeditor', 
    'djangocms_link', 
    'djangocms_file', 
    'djangocms_picture', 
    'djangocms_video', 
    'djangocms_googlemap', 
    'djangocms_snippet', 
    'djangocms_style', 
    'djangocms_column', 
    'aldryn_bootstrap3', 
    'parler', 
    'aldryn_apphooks_config', 
    'aldryn_categories', 
    'aldryn_common', 
    'aldryn_newsblog', 
    'aldryn_people', 
    'aldryn_reversion', 
    'aldryn_translation_tools', 
    'sortedm2m', 
    'taggit', 
    'reversion', 
    'aldryn_boilerplates', 
    'absolute', 
    'aldryn_forms', 
    'aldryn_forms.contrib.email_notifications', 
    'captcha', 
    'emailit', 
) 

MIDDLEWARE_CLASSES = (
    'cms.middleware.utils.ApphookReloadMiddleware', 
    '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', 
    'django.middleware.locale.LocaleMiddleware', 
    'cms.middleware.user.CurrentUserMiddleware', 
    'cms.middleware.page.CurrentPageMiddleware', 
    'cms.middleware.toolbar.ToolbarMiddleware', 
    'cms.middleware.language.LanguageCookieMiddleware', 

) 

ROOT_URLCONF = 'iboyko.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', 
       'sekizai.context_processors.sekizai', 
       'cms.context_processors.cms_settings', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'app_name.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' 

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/' 

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, "static"), 
] 



MEDIA_URL = "/media/" 
MEDIA_ROOT = os.path.join(BASE_DIR, "media") 

SITE_ID = 1 

LANGUAGES = [ 
    ('en', 'English'), 
    ('de', 'German'), 
] 

CMS_TEMPLATES = [ 
    ('base.html', 'Home page template'), 
] 

THUMBNAIL_HIGH_RESOLUTION = True 

THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace', 
    'easy_thumbnails.processors.autocrop', 
    'filer.thumbnail_processors.scale_and_crop_with_subject_location', 
    'easy_thumbnails.processors.filters' 
) 

wsgi.conf:

# NOTE: mod_wsgi can not coexist in the same apache process as 
# mod_wsgi_python3. Only load if mod_wsgi_python3 is not 
# already loaded. 

<IfModule !wsgi_module> 
LoadModule wsgi_module modules/mod_wsgi.so 
</IfModule> 

#WSGIScriptAlias /test_wsgi /var/www/vhosts/app_name/test_wsgi.py 
#WSGIScriptAlias//var/www/vhosts/app_name/app_name/wsgi.py 
WSGIPythonPath /var/www/vhosts/app_name-blog/app_name-blog-env:/var/www/vhosts/app_name-blog/app_name-blog-env/lib/pyth$ 
WSGIPythonHome /var/www/vhosts/app_name-blog/app_name-blog-env 

<VirtualHost *:80> 
    # This is name based virtual hosting. So place an appropriate server name 
    # here. Example: django.devsrv.local 
    ServerName app_name.com 

    WSGIDaemonProcess iboyko python-home=/var/www/vhosts/app_name-blog/app_name-blog-env 
    WSGIProcessGroup %{GLOBAL} 

    # Insert the full path to the wsgi.py-file here 
    WSGIScriptAlias//var/www/vhosts/app_name-blog/app_name/wsgi.py 

    <Directory /var/www/vhosts/app_name-blog/> 
     Require all granted 
    </Directory> 

    Alias /static/ /var/www/vhosts/app_name-blog/static/ 

    <Directory /var/www/vhosts/app_name-blog/static/> 
    Order deny,allow 
    Allow from all 
    </Directory> 

    Alias /media/ /var/www/vhosts/app_name-blog/media/ 
    <Directory /var/www/vhosts/app_name-blog/media/> 
    Order deny,allow 
    Allow from all 
    </Directory> 
#Alias /static/admin/ /var/www/vhosts/app_name-blog/app_name-blog-env/lib/python3.5/site-packages/django/contri$ 
    #Alias /static/admin/ /var/www/vhosts/app_name-blog/static/admin 
    # PROCESS_NAME specifies a distinct name of this process 
    # see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess 
    # PATH/TO/PROJECT_ROOT is the full path to your project's root directory, 
    # containing your project files 
    # PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full 
    # path to its directory. 
    # Generally you must specify the path to Python's site-packages. 
    #WSGIDaemonProcess {{ project_name }} python-path={{ project_directory }}:{{ project_directory }}/../lib$ 
    #WSGIPythonPath /var/www/vhosts/app_name/:/var/www/vhosts/app_name/app_name-site/lib/python3.6/site-packages/ 

    # PROCESS_GROUP specifies a distinct name for the process group 
    # see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup 
    #WSGIProcessGroup {{ project_name }} 

</VirtualHost> 

回答

0

總之,確保djangocms_admin_style安裝,確保STATIC_ROOT變量在settings.py文件和設置點到希望從中提供靜態文件的絕對路徑是解決此問題的先決條件。

pip install djangocms_admin_style

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) STATIC_ROOT = os.path.join(BASE_DIR, "static")

最後,運行以下命令修復該問題:

python manage.py collectstatic

的wsgi.py文件保持不變。

相關問題