配置

安装目录 D:\PythonWebSW\(免安装) d:\Program Files\ (安装版)

工作目录 E:/PythonWeb/code

项目名称 voith_sales

Installation

Python2.7.3

http://www.python.org/getit/releases/2.7.3/

http://www.python.org/download/

Windows x86 MSI Installer (2.7.3)
(sig)

安装

安装路径: D:\Python27 (example)

Add path for python

把D:\Python27加入环境变量Path,这样Python命令可以在任意路径执行

D:\Python32\;

Open cmd, type python, if you can find above information, it means the python works.

 

 

Django1.5.5

文件路径; D:\Django-1.5.5 (example)

安装命令

cd D:\Django-1.5.5

python setup.py install

Django会在python Lib目录下面创建新的目录:
d:\Python27\Lib\site-packages\django

….

byte-compiling d:\Python27\Lib\site-packages\django\views\i18n.py to i18n.pyc

byte-compiling d:\Python27\Lib\site-packages\django\views\static.py to static.py

……

byte-compiling d:\Python27\Lib\site-packages\django\views\__init__.py to __init_

_.pyc

byte-compiling d:\Python27\Lib\site-packages\django\__init__.py to __init__.pyc

running install_scripts

creating d:\Python27\Scripts

copying build\scripts-2.7\django-admin.py -> d:\Python27\Scripts

running install_egg_info

Writing d:\Python27\Lib\site-packages\Django-1.5.5-py2.7.egg-info

把D:\Python27\Lib\site-packages\加入环境变量

把d:\Python27\Script加入环境变量Path,这样django-admin.py可以在任意目录运行

 

Mysql 5.6

安装版

 

Note: MySQL Installer is 32 bit, but will install both 32 bit and 64 bit binaries.

http://dev.mysql.com/downloads/mysql/

 

免安装版

1) 解压到本地目录D:\PythonWebSW\mysql (example)

2) 讲D:\PythonWebSW\mysql\bin添加到环境变量Path

3) 配置my.ini

4) 安装 mysqld –install

5) 删除 mysqld –remove

6) 启动 net start mysql

7) Start SQL

 

常见问题1: Install/Remove of the Service Denied! -> Cmd should be run with "Run As Administrator"

 

MySQLLdb

你还需要从 http://www.djangoproject.com/r/python-mysql/下载安装 MySQLdb 。

安装源文件为:MySQL-python-1.2.3.win-amd64-py2.7.exe

安装的文件包括:

D:\PythonWebSW\Python27\Lib\site-packages\MySQL_python-1.2.3-py2.7.egg-info

D:\PythonWebSW\Python27\Lib\site-packages\MySQLdb

 

创建database (SQL)

C:\WINDOWS\system32>mysql -uroot -p123

mysql> create database sales;

Import exist database

cd d:\PythonWebSW\mysql\bin

mysql -uroot -p123 sales < c:\aa.txt

Export database

mysqldump -uroot -p123 sales > D:/eclipse-workspace/voith_sales/Rail/database_sales_backup.txt

 

创建database (django)

 

Create database, refer to setting.py file for the configuration

 

 

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.

'NAME': 'sales', # Or path to database file if using sqlite3.

# The following settings are not used with sqlite3:

'USER': 'root',

'PASSWORD': '123',

'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.

'PORT': '', # Set to empty string for default.

}

}

 

Create table

Enter project directory (E:/PythonWeb/code/voith_sales/Rail/),

python manage.py syncdb

 

D:\eclipse-workspace\voith_sales>python manage.py syncdb

Creating tables ...

Creating table area

Creating table country

Creating table region

…..

Creating table django_flatpage

Creating table django_admin_log

 

You just installed Django's auth system, which means you don't have any superusers defined.

Would you like to create one now? (yes/no): y

Please enter either "yes" or "no": yes

Username (leave blank to use 'alu'): alu

Email address:

Password:123

Password (again):123

Superuser created successfully.

Installing custom SQL ...

Installing indexes ...

Installed 0 object(s) from 0 fixture(s)

mysql-workbench

mysql-workbench-community-6.0.8-win32

 

Backup

命令在DOS的[url=file://\\mysql\\bin]\\mysql\\bin[/url]目录下执行

 

 

导出文件默认是存在mysql\bin目录下
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
e.g. mysqldump -u user_name -p123456 database_name > outfile_name.sql

 

[root@localhost bin]# pwd

/usr/local/mysql/bin

[root@localhost bin]# mysqldump -uroot -p123 lab_mgr > lab_mgr_backup_2015-01-03.txt

 

mysqldump备份

mysqldump -u用户名 -p密码 -h主机
数据库 a -w "sql条件" --lock-all-tables > 路径

案例:

mysqldump -uroot -p1234 -hlocalhost db1 a -w "id in (select id from b)" --lock-all-tables > c:\aa.txt

 

mysql还原

mysql -u用户名 -p密码 -h主机
数据库 < 路径

案例:

mysql -uroot -p1234 db1 < c:\aa.txt

 

command

connect

mysql –uroot -p

如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是: mysql>

 

 

Apache2.2

Apache2.4 (Win64)

免安装版

1. 安装文件httpd-2.2.19-win64.rar, 解压到"D:/PythonWebSW/httpd-2.2.19-win64

2. Configuration

conf/httpd.conf

ServerRoot "/httpd-2.2-x64"

DocumentRoot "/httpd-2.2-x64/htdocs"

<Directory "/httpd-2.2-x64/cgi-bin">

ScriptAlias /cgi-bin/ "/httpd-2.2-x64/cgi-bin/"

替换为

ServerRoot "D:/PythonWebSW/httpd-2.2.19-win64"

DocumentRoot "D:/PythonWebSW/httpd-2.2.19-win64/htdocs"

<Directory "D:/PythonWebSW/httpd-2.2.19-win64/cgi-bin">

ScriptAlias /cgi-bin/ "D:/PythonWebSW/httpd-2.2.19-win64/cgi-bin/"

 

conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/httpd-2.2-x64/docs/dummy-host.example.com"

ServerName dummy-host.example.com

ServerAlias www.dummy-host.example.com

ErrorLog "logs/dummy-host.example.com-error.log"

CustomLog "logs/dummy-host.example.com-access.log" common

</VirtualHost>

 

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host2.example.com

DocumentRoot "/httpd-2.2-x64/docs/dummy-host2.example.com"

ServerName dummy-host2.example.com

ErrorLog "logs/dummy-host2.example.com-error.log"

CustomLog "logs/dummy-host2.example.com-access.log" common

</VirtualHost>

替换为

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "D:/PythonWebSW/httpd-2.2.19-win64/docs/dummy-host.example.com"

ServerName dummy-host.example.com

ServerAlias www.dummy-host.example.com

ErrorLog "logs/dummy-host.example.com-error.log"

CustomLog "logs/dummy-host.example.com-access.log" common

</VirtualHost>

 

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host2.example.com

DocumentRoot "D:/PythonWebSW/httpd-2.2.19-win64/docs/dummy-host2.example.com"

ServerName dummy-host2.example.com

ErrorLog "logs/dummy-host2.example.com-error.log"

CustomLog "logs/dummy-host2.example.com-access.log" common

</VirtualHost>

 

3.安装

D:\PythonWebSW\httpd-2.2.19-win64\bin>httpd -k install

 

D:\httpd-2.2.19-win64\bin>httpd -k install

Installing the Apache2.2 service

The Apache2.2 service is successfully installed.

Testing httpd.conf....

Errors reported here must be corrected before the service can be started.

httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.101 for ServerName

(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

原因及解决:有可能是系统80端口默认被占用了

修改conf/httpd.conf

Listen 80 è Listen 8081

 

4.启动

D:\PythonWebSW\httpd-2.2.19-win64\bin>start httpd

5.卸载

D:\PythonWebSW\httpd-2.2.19-win64\bin>httpd -k uninstall

常见问题

Issue1 (OS 5)Access is denied. : Apache2.2: OpenService failed

如果出现这个错误,用管理员权限打开cmd

 

Issue2 (OS 1072)The specified service has been marked for deletion. : Apache2.2: Failed to delete the service.

将service里面的停掉

 

Issue3 ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

Window 安装文件

MySQL-python-1.2.3.win-amd64-py2.7.exe

Linux:

MySQL-python==1.2.3

生成的文件如下

MySQL_python-1.2.3-py2.7.egg-info (文件夹)

MySQLdb (文件夹)

_mysql.pyd

_mysql_exceptions.py

_mysql_exceptions.pyc

_mysql_exceptions.pyo

案例:

在系统里安装,但是virtualenv的package没安装的话,运行会出错,可以从系统安装文件里将这些文件拷过去,或者在virtualenv里安装

 

Issue4机器上可能会配置多个apache,有的时候安装新的apache时需要先把之前install的uninstall

Issue5: Django: AppRegistryNotReady()

In django.wsgi, 添加setup()

os.environ['DJANGO_SETTINGS_MODULE'] = "ecommerce2.settings"

import django

django.setup()

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

 

参考 http://stackoverflow.com/questions/24793351/django-appregistrynotready

setup()

This function is called automatically:

  • When running an HTTP server via Django's WSGI support.
  • When invoking a management command.

It must be called explicitly in other cases, for instance in plain Python scripts.

 

不知道为什么,并不是所有的项目都需要这样

 

Test : http://localhost:8081

It works!

 

安装版

Download and install Apache 2.2

 

My installation location : d:\Program Files\

http://httpd.apache.org/download.cgi

WIN64: http://pan.baidu.com/share/link?shareid=364454&uk=2902956560

 

Download and configure mod_wsgi

Download mod_wsgi.so

Note: the version need match the python and apache version

http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py27-3.3.so

http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

file: mod_wsgi-3.4.ap22.win-amd64-py2.7.zip

 

mod_wsgi-3.4-Win64(apache2.4).zip: http://pan.baidu.com/share/link?shareid=364450&uk=2902956560

 

Installation

Put mod_wsgi.so in d:\Program Files\Apache Software Foundation\Apache2.2\modules\

Configure apache to load wsgi

httpd.conf

d:\Program Files\Apache Software Foundation\Apache2.2\conf\

add:

LoadModule wsgi_module modules/mod_wsgi.so

 

Note : let apache load wsgi module, you can also use your self-defined name

Configure httpd

搜索http.conf文件,把"Deny from all" 及 "Require all denied" 等语句全部注释掉:

 

<Directory />

Options FollowSymLinks

AllowOverride None

Require all denied

Order deny,allow

Deny from all

</Directory>

修改为为

<Directory />

Options Indexes FollowSymLinks

AllowOverride None

</Directory>

 

 

test wsgi

 

添加test.wsgi

Include "D:/eclipse-workspace/voith_sales/Rail/apache/test.wsgi "

 

 

test wsgi configuration, 只是测试脚本,正式脚本里面需要把他们注释掉

test.wsgi

def application(environ, start_response):

status = '200 OK'

output = 'Hello World!'

 

response_headers = [('Content-type', 'text/plain'),

('Content-Length', str(len(output)))]

start_response(status, response_headers)

 

return [output]

 

 

Test : http://localhost:8081

 

Configure apache to load project

Create a folder "apache" under your project directory to locate your apache configuration file "django.wsgi" & "apache_django_wsgi.conf", it's not mandatory, dedicated folder is for maintenance purpose

比起前面的test.wsgi我们也可以用这个方法

Include "E:/PythonWeb/code/voith_sales/Rail/apache/apache_django_wsgi.conf"

 

Note : let apache load configuration file, you can also configure it in httpd.conf directly, using external file will benefit your maintenance

 

apache_django_wsgi.conf

测试项目

WSGIScriptAlias / "E:/PythonWeb/code/voith_sales/Rail/apache/test.wsgi"

<Directory "E:/PythonWeb/code/voith_sales/Rail">

Options FollowSymLinks

AllowOverride None

Order deny,allow

Allow from all

</Directory>

 

实际项目

WSGIScriptAlias / "D:/eclipse-workspace/voith_sales/Rail/apache/django.wsgi"

<Directory " D:/eclipse-workspace/voith_sales/Rail">

Options FollowSymLinks

AllowOverride None

Order deny,allow

Allow from all

</Directory>

 

django.wsgi

import os

import sys

 

#Calculate the path based on the location of the WSGI script.

apache_configuration= os.path.dirname(__file__)

project = os.path.dirname(apache_configuration)

workspace = os.path.dirname(project)

sys.stdout = sys.stderr

sys.path.append(workspace)

#sys.path.append('E:/PythonWeb/code/voith_sales')

 

os.environ['DJANGO_SETTINGS_MODULE'] = "Rail.settings_product"

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

 

configure static resource

apache_django_wsgi.conf

Alias /index/Rail/static "E:/PythonWeb/code/voith_sales/Rail/static"

<Directory "E:/PythonWeb/code/voith_sales/Rail/static">

Order allow,deny

Allow from all

</Directory>

 

Settings.py

STATIC_URL = '/index/Rail/static/'

 

copy static data to D:/eclipse-workspace/voith_sales/Rail/static from django source,不要手动拷贝,用python manage.py collectstatic

 

 

Restart apache

 

Uninstallation

 

python很好用,尤其是用过easy_install的朋友更是觉得它的便捷,

卸载命令也很简单 easy_install -m package-name

但是面对源码安装的怎么办呢?

setup.py 帮助你纪录安装细节方便你卸载

python setup.py install --record log

这时所有的安装细节都写到 log 里了

想要卸载的时候

cat log | xagrs rm -rf

就可以干净卸载了

[转]对于python setup.py install安装的包如何卸载

 

virtualenv

eclipse configuration in virtualenv

Windows->Preferences->PyDev->Interpreters->Python Interpreters

Add "Lib/site-packages" of your virtual environment to System PYTHONPATH

Run apache in virtualenv

Deploy Django on Apache with Virtualenv and mod_wsgi

How to Run Django with mod_wsgi and Apache with a virtualenv Python environment on a Debian VPS

还没验证,好像不需要这些配置也能工作,他们是怎么找过去的?

 

SAE部署

新浪云

SAE的配置文件主要有两个:config.yaml和index.wsgi

index.wsgi

import sys

import os.path

 

os.environ['DJANGO_SETTINGS_MODULE'] = 'YOUR_APP_NAME.settings'

sys.path.append(os.path.join(os.path.dirname(__file__), 'YOUR_APP_NAME'))

 

import sae

from YOUR_APP_NAME import wsgi

 

application = sae.create_wsgi_app(wsgi.application)

注意:只需要简单地将其中的YOUR_APP_NAME替换成你的应用的名称就行了,不要加其他任何符号

 

config.yaml

参考SAE应用程序配置文档

name: YOUR_APP_NAME

version: 1

 

libraries:

- name: django

version: "1.5"

 

静态文件

url.py 增加配置如下

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()

 

config.yaml改为

handlers:

- url: /static/

  static_dir: ./

 

数据库sql导入

-- LOCK TABLES `auth_permission` WRITE;

/*!40000 ALTER TABLE `auth_permission` DISABLE KEYS */;

INSERT INTO `auth_permission` VALUES (1,'Can add product_class',1,'add_product_class'),(2,'Can ………….PreCI_Request',32,'delete_preci_request');

/*!40000 ALTER TABLE `auth_permission` ENABLE KEYS */;

-- UNLOCK TABLES;

 

LOCK/UNLOCK 需删除,否则报错

 

参考文档

http://www.hi-beiyu.com/archives/141

Deploy Django in Windows的更多相关文章

  1. Python和Django在Windows上的环境搭建

    作为一个.NET程序员,真心不喜欢Python以及PHP这种松散的语法.有人说,程序员应该多学几门语言,本想学习Java,无奈感觉Java的语法太啰嗦了.很多人都推荐Python,说它的语法简洁,执行 ...

  2. nginx + django on windows

    It's quite simple to run django on nginx on windows. Here are some key steps to follow - 1. Download ...

  3. django在windows设置定时任务,勉强能用

    推荐三篇文章 [Django]Django 定时任务实现(django-crontab+command) django中使用定时任务执行某些操作时的规范操作 windows配置crontab 前两篇文 ...

  4. Nginx + FastCGI + Django在windows上部署及nginx常用命令

    一般应用都是部署在linux系统上,不会在windows上部署,emmm..所以有兴趣的就瞧瞧吧哈哈 nginx工作原理: nginx用于处理静态文件,动态部分经由fastcgi .scgi或uWSG ...

  5. django在windows下的经历

    django-admin.py startproject project_name 去掉.py 常见命令:https://blog.csdn.net/weixin_42134789/article/d ...

  6. [django] Deploy Django Applications Using uWSGI and Nginx on Ubuntu 14.04

    关键点1:chmod-socket=666 (mysite_uwsgi.ini) 关键点2 : 工程目录和虚拟环境目录搞清楚 几个参考: http://uwsgi-docs.readthedocs.i ...

  7. Django在windows系统下安装详情

    1. Django 下载地址:https://www.djangoproject.com/download/ 2. 解压到跟python安装目录平级目录: 如下图: 3.通过cmd控制台安装djang ...

  8. pycharm建立第一个django工程-----windows中

    pycharm建立第一个django工程 系统:win764 ip: 192.168.0.100 安装django pip install django 左上角建立一个名为Firstdjango工程 ...

  9. DJango安装-windows

    1.进入虚拟环境后启动 activate 2.查看当前虚拟环境是否存在Django环境 pip list 3.不存在则 安装Django环境 pip install django 4.查看Django ...

随机推荐

  1. .net程序员求职简历

    .net程序员求职简历 个人概况 姓名 齐志超 学历 专科 毕业学校 河北软件职业技术学院 专业 软件开发与设计 手机 18730269286 年龄 22 性别 男 现居住地 北京 电子邮件 qzc9 ...

  2. linux下如何使用USB存储设备

    如何在Linux环境中使用USB接口的 存储 设备?这是各大电脑论坛上出现得比较多的一个问题,同此可见这也是摆在许多电脑玩家面前的一道难题. 本文就为您提供一套完美的解决方案,通过下面的方法,您仅可以 ...

  3. android jni ndk 视频分享

    链接如下:http://download.csdn.net/detail/jltxgcy/5667327.

  4. 机器学习( Machine Learning)的定义

    关于机器学习有两个相关的定义: 1)给计算机赋予没有固定编程的学习能力的研究领域. 2)一种计算机的程序,能从一些任务(T)和性能的度量(P),经验(E)中进行学习.在学习中,任务T的性能P能够随着P ...

  5. 如何把微信语音汇总成一个MP3文件?

    有的时候想要保存微信中的语音内容,但是苦于语音短且多,因此想要把它汇总成一个音频文件. 本篇以苹果手机为例,安卓手机也可类似. 第一步,安装同步助手 同步助手是一款在电脑上安装,可以保存手机上的内容的 ...

  6. 【Java每日一题】20170110

    20170109问题解析请点击今日问题下方的"[Java每日一题]20170110"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  7. 分别使用Hadoop和Spark实现二次排序

    零.序(注意本部分与标题无太大关系,可直接调至第一部分) 既然没用为啥会有序?原因不想再开一篇文章,来抒发点什么感想或者计划了,就在这里写点好了: 前些日子买了几本书,打算学习和研究大数据方面的知识, ...

  8. hdu1039

    #include<stdio.h>#include<string.h>const int MAXN=200;char str[MAXN]; bool isvowel(char ...

  9. 第一百三十三节,JavaScript,封装库--弹出登录框

    JavaScript,封装库--弹出登录框 封装库,增加了两个方法 yuan_su_ju_zhong()方法,将获取到的区块元素居中到页面,chuang_kou_shi_jian()方法,浏览器窗口事 ...

  10. Ueditor文件上传问题

    我们在做一些网站是会遇到,要有上传文件一类的事情. 我发现百度的富文本编辑器带上传功能,但是没有办法给后台传递我们要的参数. 先在ueditor.all.js中找到, me.execCommand(' ...