linux下安装mod_python和django笔记

安装 mod_python

1、到 www.modpython.org

 下载源码包,解压得到目录,进入该目录,执行:

 

 ./configure --with-apxs=/opt/apache/bin/apxs --with-python=/usr/bin/python2.7

 make

 make install
 

完毕之后,mod_python 会在 /opt/apache/modules 中添加 mod_python.so 库文件,并且在 /opt/python/2.7/lib/python2.7/site-packages 中添加 mod_python 包。

如果编译程序没有检测到 apache 和 python,会报错退出。

 

 

如果你将mod_python编译成DSO,那么你需要通过在Apache的配置文件(通常称为httpd.conf 或者 apache.conf)里面加入如下一行,来载入模块:

    LoadModule python_module modules/mod_python.so

例子

<Location "/blog">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE zlblog.settings
PythonInterpreter zlblog
PythonDebug On
</Location>

 留给静态文件一个缝隙

<Location "/blog/(images|css|js)">
SetHandler none
</Location>

 

------------------

注意这里有一个bug

connobject.c: In function '_conn_read':

connobject.c:142: error: request for member 'next' in something not a structure

or union

apxs:Error: Command failed with rc=65536

.

make[1]: *** [mod_python.so] Error 1

make[1]: Leaving directory `/usr/src/rpm/BUILD/mod_python-3.3.1/src'

make: *** [do_dso] Error 2

需修改mod_python-3.3.1/src/connobject.c中

!(b == APR_BRIGADE_SENTINEL(b)

为

!(b == APR_BRIGADE_SENTINEL(bb)

--------------

 

 

 

2.安装django

   下载django包后解压,运行

python setup.py install
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是Python中使用Django进行通讯录制作的步骤: 1. 创建Django项目 使用以下命令创建Django项目: ``` django-admin startproject myaddressbook ``` 2. 创建Django应用 使用以下命令创建Django应用: ``` python manage.py startapp contacts ``` 3. 配置数据库 打开myaddressbook/settings.py文件,配置数据库: ```python DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } ``` 这里我们使用sqlite3数据库,如果你想使用其他数据库,需要在此处进行相应的配置。 4. 创建模型 在contacts/models.py文件中定义Contact模型: ```python from django.db import models class Contact(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() phone = models.CharField(max_length=20) def __str__(self): return f'{self.first_name} {self.last_name}' ``` 5. 迁移数据库 运行以下命令迁移数据库: ``` python manage.py makemigrations python manage.py migrate ``` 6. 创建视图 在contacts/views.py文件中创建ContactListView视图: ```python from django.views.generic import ListView from .models import Contact class ContactListView(ListView): model = Contact ``` 7. 创建URL 在myaddressbook/urls.py文件中创建URL: ```python from django.urls import path from contacts.views import ContactListView urlpatterns = [ path('', ContactListView.as_view(), name='contact_list'), ] ``` 8. 运行服务器 使用以下命令运行Django服务器: ``` python manage.py runserver ``` 现在你可以在浏览器中访问http://127.0.0.1:8000/,就可以看到通讯录列表了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值