正文
Put your code in some directory outside of the document root, such as /home/mycode.
Django代码应该放在什么地方?
如果你使用的是老式的PHP(没有现代框架)你可能习惯于把代码放在Web服务器根目录下(例如/var/www)。而在Django中不建议你这么做,因为这是一个不好的习惯,因为这增加了人们通过网络直接查看你代码的可能性,这会降低网站的安全性。
把你的代码放在 别的 地方,例如/home/mycode
Let’s look at what startproject created:
我们来看看 startproject 创建了什么:
These files are:
这些文件的含义如下:
外部的mysite仅仅是你项目的容器而已,它的名字不会影响到Django的运行,你可以把它改成你喜欢的名字。
manage.py:是一个供你在命令行使用的管理工具,你可以通过它来管控你的项目,你可以点击 这里 查看更多细节。
The inner mysite/directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. urls).
内部的mysite目录才是你的项目本体,它的名字就是你的包名,如果你需要引用它以及内部的模块,你可以直接import它(例如:mysite.urls)。
mysite/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, readin the official Python docs.
mysite/__init__.py:一个空文件,它的作用只是向python表明这是一个python包。如果你还是不太清楚,建议你先阅读 python文档中包的部分 。
mysite/settings.py: Settings/configuration for this Django project. Django settingswill tell you all about how settings work.
mysite/settings.py:设置/配置这个Django项目,点击 这里 查看配置是如何工作的。
mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
mysite/urls.py:这是这个项目的url声明,也是你网站的目录,也可以查看 url调度 获取更多细节。
mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGIfor more details.
mysite/wsgi.py:一个兼容WSGI入口点的Web服务器为您服务。参阅 如何使用WSGI 。
The development server
开发服务器
Let’s verify your Django project works. Change into the outer mysite directory, if you haven’t already, and run the following commands:
让我们来验证你的服务器能否正常运作吧。切换到外层的mysite目录,输入以下命令:
You’ll see the following output on the command line:
你将会看到如下输出:
Note
Ignore the warning about unapplied database migrations for now; we’ll deal with the database shortly.
注意
我们现在暂时忽略数据库迁移的警告,稍后我们会进行处理。
You’ve started the Django development server, a lightweight Web server written purely in Python. We’ve included this with Django so you can develop things rapidly, without having to deal with configuring a production server – such as Apache – until you’re ready for production.
你已经启动了一个由Django开发的服务器了,这是一个纯python编写的轻量级服务器,我们将这个服务器内置在Django中,所以你可以快速开发项目而无需花精力去思考如何配置生产服务器(就像Apache那样),直到你已经准备好生产了为止。