django+apache配置

来源:互联网 发布:淘宝卖家怎么设置折扣 编辑:程序博客网 时间:2024/05/24 22:45

1.   准备工作

l  安装apache

l  安装mod_wsgi.so

l  安装django

l  新建一个django工程

(这里就不详细介绍安装了)

 

2. 配置wsgi.py

import osimport sysfrom os.path import join,dirname,abspathfrom django.core.wsgi import get_wsgi_application#PROJECT_DIR = dirname(dirname(dirname(abspath(__file__))))PROJECT_DIR = dirname(dirname(abspath(__file__)))sys.path.insert(0, PROJECT_DIR)os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello.settings")application = get_wsgi_application()


3. 配置settings.py

"""Django settings for hello project.Generated by 'django-admin startproject' using Django 1.8.2.For more information on this file, seehttps://docs.djangoproject.com/en/1.8/topics/settings/For the full list of settings and their values, seehttps://docs.djangoproject.com/en/1.8/ref/settings/"""# Build paths inside the project like this: os.path.join(BASE_DIR, ...)import osimport sysBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))sys.path.insert(0, os.path.join(BASE_DIR, 'app'))# 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 = 'tk#=1l+)k6qwrg3n0+qb1(j9^c^7_zgnr69g-cjw1c2j6#do_*'# SECURITY WARNING: don't run with debug turned on in production!DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = (    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles',    'app',)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 = 'hello.urls'# List of finder classes that know how to find static files in# various locations.STATICFILES_FINDERS = (    'django.contrib.staticfiles.finders.FileSystemFinder',    'django.contrib.staticfiles.finders.AppDirectoriesFinder',)STATICFILES_DIRS = (    os.path.join(BASE_DIR, 'app'),)# List of callables that know how to import templates from various sources.TEMPLATE_LOADERS = (    'django.template.loaders.filesystem.Loader',    'django.template.loaders.app_directories.Loader',)TEMPLATE_DIRS = (    os.path.join(BASE_DIR, 'app'),)WSGI_APPLICATION = 'hello.wsgi.application'# Database# https://docs.djangoproject.com/en/1.8/ref/settings/#databasesDATABASES = {    '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 = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.8/howto/static-files/STATIC_ROOT = os.path.join(BASE_DIR, 'static')STATIC_URL = '/WebApi/'

4. 收集静态文件


在工程的根目录下,执行命令

python manage.py collectstatic

5. 配置http.conf

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / "/home/zhubao/Code/django_code/hello/hello/wsgi.py"<Directory "/home/zhubao/Code/django_code/hello/hello">    Order Deny,Allow    Allow from all</Directory>Alias /WebApi "/home/zhubao/Code/django_code/hello/static"<Directory "/home/zhubao/Code/django_code/hello/static">    Order Allow,Deny    Allow from all    IndexOptions FancyIndexing</Directory>


基本上算是配置结束了。




0 0
原创粉丝点击