windows python2.7 django 开发环境搭建

一、需要下载的工具:

python2.7

PIL-1.1.6.win32-py2.7

Django book 2.0 中文版 (非常有用的教程: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.7

安装到 d:/Python27

接下来添加环境变量到path:d:\Python27;d:\Python27\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的安装路径

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/
<Location “/”>
SetHandler python-program
PythonPath “sys.path+['d:/django_test']“
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonInterpreter mysite
PythonDebug On
</Location>

#Alias /site_media 是用来将 mysite的静态文件设置一个 URL 访问的别名。
Alias /site_media d:/django_test/mysite/media
<Location “/site_media/”>
SetHandler None
</Location>
#Alias /media 是将 Django Admin 的静态文件设置一个 URL 的访问别名。
Alias /media c:/Django-1.1.1/django/contrib/admin/media
<Location “/media/”>
SetHandler None
</Location>

#配置静态文件权限,让apache有权访问
<Directory “c:/python26/Lib/site-packages/django/contrib/admin/media”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

MaxRequestsPerChild 1
# file types we want to serve statically
# case insensative match
<LocationMatch “(?i)\.(jpg|gif|png|txt|ico|pdf|css|jpeg)$”>
SetHandler None
</LocationMatch>

常见错误及解决方案见: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lanlandechong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值