Django Hello World app

写hello world程序,可以参考:http://djangobook.py3k.cn/chapter02/ecn/

第一章和第二章。里面讲到了安装和建立demo project.

注意,按照例子做的话,这个demo的站点不能外发,因为有安全性考虑。

The Development Server

开发服务器

Django includes a built-in, lightweight Web server you can use while developing your site. Weve included this server so you can develop your site rapidly, without having to deal with configuring your production Web server (e.g., Apache) until youre ready for production. This development server watches your code for changes and automatically reloads, helping you make many rapid changes to your project without needing to restart anything.

Django 带有一个内建的轻量级 Web 服务器,可供站点开发过程中使用。我们提供这个服务器是为了让你快速开发站点,也就是说在准备发布产品之前,无需进行产品级 Web 服务器(比如 Apache)的配置工作。该开发服务器会监测代码变动并将其自动重载,这样一来,你可快速进行项目修改而无需作任何重启。

Change into the mysite directory, if you havent already, and run the command python manage.py runserver . Youll see something like this:

如果还没有进入 mysite 目录的话,现在进入其中,并运行 python manage.py runserver 命令。你将看到如下输出:

Validating models…

0 errors found.

Django version 1.0, using settings ‘mysite.settings’

Development server is running at http://127.0.0.1:8000/

Quit the server with CONTROL-C.

Although the development server is extremely nice for, well, development, resist the temptation to use this server in anything resembling a production environment. The development server can handle only a single request at a time reliably, and it has not gone through a security audit of any sort. When the time comes to launch your site, see Chapter 20 for information on how to deploy Django.

尽管对于开发来说,这个开发服务器非常得棒,但一定要打消在产品级环境中使用该服务器的念头。在同一时间,该服务器只能可靠地处理一次单个请求,并且没有进行任何类型的安全审计。发布站点前,请参阅第 20 章了解如何部署 Django 。

Changing the Host or the Port

更改主机或端口

By default, the runserver command starts the development server on port 8000, listening only for local connections. If you want to change the servers port, pass it as a command-line argument:

默认情况下, runserver 命令在 8000 端口启动开发服务器,且只监听本机连接。要想要更改服务器端口的话,可将端口作为命令行参数传入:

python manage.py runserver 8080

You can also change the IP address that the server listens on. This is especially helpful if youd like to share a development site with other developers. The following:

还可以改变服务器监听的 IP 地址。要和其他开发人员共享同一开发站点的话,该功能特别有用。下面的命令:

python manage.py runserver 0.0.0.0:8080

will make Django listen on any network interface, thus allowing other computers to connect to the development server.

会让 Django 监听所有网络接口,因此也就让其它电脑可连接到开发服务器了。

Now that the servers running, visit http://127.0.0.1:8000/ with your Web browser. Youll see a Welcome to Django page shaded a pleasant pastel blue. It worked!

既然服务器已经运行起来了,现在用网页浏览器访问 http://127.0.0.1:8000/ 。 你应该可以看到一个欢快的淡蓝色所笼罩的 Django 欢迎页面。一切正常!

通过.

 Posted by  at 17:02  Tagged with: 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值