Django install in win7

(转)Django的windows vista安装与初步使用(1) http://hi.baidu.com/kxw102/blog/item/0e25f63f163983ea838b137f.html
2010-11-20 21:45
1.首先安装python, 我安装了Python2.5的版本,安装在了C:\Python25\
2.接着安装django,我下载了django 1.2.3的版本。
3. 安装完了之后,打开cmd,然后可以检验是否安装的顺利,输入python;接着输入import django;接着输入django.get_version()或者django.VERSION

4. 记住,安装前一定要把以前的版本删除掉:
If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.

If you installed Django using setup.py install, uninstalling is as simple as deleting the django directory from your Python site-packages.

If you installed Django from a Python egg, remove the Django .egg file, and remove the reference to the egg in the file named easy-install.pth. This file should also be located in your site-packages directory.

安装完了之后按照教程可以:
1. 输入django-admin.py startproject mysite,然后就可以自动建立一个mysite的文件夹,
2. 接着再输入cd mysite;
3. 然后python manage.py runserver就可以运行这个server了;
4. 接下来可以在网上输入 http://127.0.0.1:8000/即可以访问。

好了,上面是官方的用法,可是我在执行第一步的时候就发生了错误,无法找到文件,后来按照官方说明又把C:\Python26\Scripts加入到环境变量的path中,可是还是发生找不到文件的问题;接着我反复试来试去,发现原来自己复制错误,我安装的是python2.5, 但是复制的却是
C:\Python26\Scripts; 
修改完之后运行第一条命令,发现不管我在
django-admin.py后面输入任何参数,输出的都是 django-admin.py的帮助文件,我左思不得其解。 于是就查看了 C:\Python26\Scripts\django-admin.py的内容,然后它把我指引到了 C:\Python25\Lib\site-packages\django\core\management\_init_.py 的文件,文件里面的 ManagementUtility  class里面的excute()函数 是一个很有用的函数,它读取命令行中的参数。我发现,不管我怎么在命令行里面输入,结果都是没有输入命令,所以所有的subcommand都变成了help,怪不得每次都给我显示帮助文件呢。从这里我才学会了python如何从CMD的命令行里读取参数,于是我写下了(原创)Python如何读取命令行的参数--sys.argv的教程,得出结论就是如果想读取命令行,一定要用python 文件.py 才能读取命令行参数。
于是,我试着用 python django-admin.py startproject mysit, 可是系统提示:python: can't open file 'django-admin.py': [Errno 2] No such file or directory 。后来从网上查找资料,发现原来是因为使用python的命令时候,只能够执行当前文件夹下面的.py 文件,所以上面肯定找不到的。于是我用如下的命令
H:\My_Project\Python\010_Django > python C:\Python25\Lib\site-packages\django\bin\
django-admin.py startproject mysite
 
如此这般,终于建立了第一个网络文件夹--mysite,
接着按照官方的方法即可以运行了。
注意:在xp下面就不用像上面那样执行了,只要用
django-admin.py startproject mysite即可。

如果想修改port的话,那么

By default, the runserver command starts the development server on the internal IP at port 8000.

If you want to change the server's port, pass it as a command-line argument. For instance, this command starts the server on port 8080:

python manage.py runserver 8080

If you want to change the server's IP, pass it along with the port. So to listen on all public IPs (useful if you want to show off your work on other computers), use:

python manage.py runserver 0.0.0.0:8000

Full docs for the development server can be found in the runserver reference.

转载于:https://www.cnblogs.com/ken-hust/archive/2012/03/25/2416748.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值