kaiser_cn 发表于 2015-11-13 14:18:58

mac+apache+django+wsgi

MAC 自带的APACHE、python

一、安装mod_wscgi

下载地址:https://pypi.python.org/pypi/mod_wsgi 、http://modwsgi.readthedocs.org/en/master/

我用的版本:mod_wsgi-4.4.10.tar

# tar -zxvf mod_wsgi-4.4.10.tar
# cd mod_wsgi-4.4.10
# ./configre
# make
# sudo make install

二、下载Django

下载地址:https://www.djangoproject.com/m/releases/1.6/Django-1.6.11.tar.gz

# tar -zxvf Django-1.6.11.tar.gz
# cd Django-1.6.11
# python setup.py install

三、APACHE 配置加载wsgi

LoadModule wsgi_module libexec/apache2/mod_wsgi.soAPACHE 虚NI域名配置
<VirtualHost *:80>
#DocumentRoot &quot;/Users/user/Project/python/djangoapp&quot;
ServerName test.djangoapp.com
WSGIScriptAlias / /Users/user/Project/python/djangoapp
AddType text/html .py
ErrorLog &quot;/private/var/log/apache2/dummy-host.example.com-error-django_log&quot;
CustomLog &quot;/private/var/log/apache2/dummy-host.example.com-access_log&quot; common
<Directory &quot;/Users/user/Project/python/djangoapp&quot;>
#Options Indexes FollowSymLinks MultiViews
#AllowOverride None
#AddHandler cgi-script cgi pl
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

四、生成项目

# django-admin.py startapp djangoapp

五、测试django 生成的WEB 是否安装成功

1.新建视图在项目目录下views.py
from django.http import HttpResponse
def hello(request):
return HttpResponse(&quot;Hello world&quot;)
2. RULconf设置 将项目下的urls.py修改成如下内容
from django.conf.urls.defaults import *
from mysite.views import
urlpatterns = patterns('',
('^hello/$', hello),
)
3. 启动Django开发服务器来测试修改好的 URLconf, 运行命令行 python manage.py runserver
打开你的浏览器访问 http://127.0.0.1:8000/hello/
如果输出hello word 就正确













版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: mac+apache+django+wsgi