windows python2.6 django 开发环境搭建

来源:互联网 发布:德勤的职业目标 知乎 编辑:程序博客网 时间:2024/04/26 03:34

一、需要下载的工具:

python2.6

PIL-1.1.6.win32-py2.6

Django-1.1.1 (非常有用的教程:Django Step by Step)

apache_2.2.14

mod_python-3.3.1.win32-py2.6-apache2.2

MySQL

MySQL-python-1.2.2

libguide40.dll 

libmmd.dll

libMySQL.dll

二、安装上面的工具

1. 安装python2.6

安装到 C:/Python26

接下来添加环境变量到path:c:/Python26;c:/Python26/Scripts;

2. 安装PIL

3. 安装django

转到django的解压目录

如:

cmd

cd /d e:/django/Django-1.1.1

继续在命令行输入如下命令开始安装django:

python setup.py install

(

让我们来试试:

建立目录d:/django_test

cd /d d:

mkdir django_test

cd django_test

django-admin.py startproject mysite

好了,你可以在django_test/mysite目录下面产生了4个.py文件:manage.py, __init__.py, urls.py, settings.py。

cd mysite

manage.py runserver

在浏览器中输入:

http://127.0.0.1:8000/

你看到Welcome to Django的页面了吗?

修改配置项目的配置文件:settings.py

首先,在mysite目录下面创建两个目录

media: 用于存放媒体文件

templates: 用于存放模板文件

mkdir media

mkdir templates

用写字板打开settings.py修改或添加:

MEDIA_ROOT = 'd:/django_test/mysite'
STATIC_PATH = 'd:/django_test/mysite/media'

TEMPLATE_DIRS = (
    "d:/django_test/mystie/tempates",
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

)

4. 安装apache

5. 安装mod_python(如果你在windows 7下安装遇到问题请Email: nanac.xu@gmail.com)

需要选择apache的安装路径

 

{

陆续有同学发邮件问我win7下安装mod_python出问题的处理方法,之前碰到过没有将处理方

法记录下来。今天把Apache删除了重新安装了一次,现在将安装方法简单记录下:
1. 安装过程中出错没有关系,安装目的其实就是将mod_python.so复制到Apache的安装目录


2. 使用7-Zip将mod_python-3.3.1.win32-py2.6-apache2.2.exe解压
3. mod_python-3.3.1.win32-py2.6-apache2.2/SCRIPTS下的win32_postinstall.py用编辑器

打开,查看下,或许你已经看出什么了
4. 将mod_python-3.3.1.win32-py2.6-apache2.2/PLATLIB目录下的所有文件及子目录复制到

Python26/Lib/site-packages目录下,然后运行mod_python-3.3.1.win32-py2.6-

apache2.2/SCRIPTS目录下使用python.exe 运行win32_postinstall.py文件

5. 选择Apache的安装路径

6. 去Program Files (x86)/Apache Software Foundation/Apache2.2/modules目录下检查

mod_python.so文件是否已经存在。

7.如果找到mod_python.so则安装成功。

}

 

6.  配置Apache的httpd.conf配置文件:

首先,在“Dynamic Shared Object (DSO) Support”的配置下增加一行

LoadModule python_module modules/mod_python.so

这个必须手动添加。

 

在配置文件的尾部添加:

#  mysite目录路径: d:/django_test/mysite,
# 但是对于PythonPath,必须设置成这个目录的上一级目录!
# this site url:http://localhost:80/

    SetHandler python-program
    PythonPath "sys.path+['d:/django_test']"
    PythonHandler django.core.handlers.modpython   
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonInterpreter mysite
    PythonDebug On

#Alias /site_media 是用来将 mysite的静态文件设置一个 URL 访问的别名。
Alias /site_media d:/django_test/mysite/media

       SetHandler None

#Alias /media 是将 Django Admin 的静态文件设置一个 URL 的访问别名。
Alias /media c:/Django-1.1.1/django/contrib/admin/media

       SetHandler None

#配置静态文件权限,让apache有权访问

    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

MaxRequestsPerChild 1
# file types we want to serve statically
# case insensative match

       SetHandler None

常见错误及解决方案见:http://isun.blog.sohu.com/88570908.html

 

在浏览器中输入:http://127.0.0.1/ 试试,看到了什么?

7. 安装mysql

安装Mysql5

安装MySQL-python-1.2.2

修改项目的配置文件:(配置数据库的连接)

DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'db_name'             # Or path to database file if using sqlite3.
DATABASE_USER = 'root'             # Not used with sqlite3.
DATABASE_PASSWORD = '***'         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

在mysql命令行输入:create database dbmclsite default charset utf8 collate utf8_unicode_ci

在windows命令行输入:python manage.py syncdb

出错啦!

DLL load failed: 找不到指定的模块. 解决方案:

1) libmmd.dll, libguide40.dll和libmySQL.dll三个dll文件复制到python安装目录的Lib/site-packages下。

2) file "__init__", replace:

from sets import ImmutableSet

class DBAPISet(ImmutableSet): 

with 

class DBAPISet(frozenset):

3) file "converters.py", remove:

from sets import BaseSet, Set

4) file "converters.py", change "Set" by "set" (IMPORTANT: only two places):

line 48: return set([ i for i in s.split(',') if i ]) 

line 128: set: Set2Str, 

OK, Let’s try!

python manage.py syncdb

It words!

到这里,环境的搭建工作就算基本完成了。

References:

http://www.3gmatrix.cn/4/viewspace-16757.html

http://hi.baidu.com/doublelook/blog/item/e7fe3918c4b6d74d42a9ad4c.html

http://isun.blog.sohu.com/88570908.html

 

二、 启用管理界面及更改管理界面的外观

http://docs.djangoproject.com/en/dev/intro/tutorial02/#customize-the-admin-form

三、 国际化

http://docs.djangoproject.com/en/1.1/topics/i18n/

需要用到的gettext工具:

http://sourceforge.net/projects/gettext/

四、 支持富文本编辑

tinymce

http://tinymce.moxiecode.com/download.php

五、常用命令

MySQL:

show databases;

use db_name;

create database db_name default character set utf8 collate utf8_unicode_ci;

show create database db_name;

show tables;

show create table_name;

 

同步数据库:

manage.py syncdb;

 

国际化:

django-admin.py makemessages –l cn-zh

django-admin.py makemessages –a

django-admin.py compilemessages

原创粉丝点击