django导包_Django项目导览

django导包

In this tutorial, we’re going to take a look on each file that exists in our django project folder.

在本教程中,我们将研究django项目文件夹中存在的每个文件。

Let’s say, we’ve created a project named as my_website on our desktop. Now open that folder you can see another folder (directory) with the same name inside our project folder.

假设我们已经在桌面上创建了一个名为my_website的项目。 现在打开该文件夹,您可以在我们的项目文件夹中看到另一个具有相同名称的文件夹(目录)。

Django Project Tour 1

Along with this directory, we’ve other two files db.sqllite3 and manage.py.

除了这个目录,我们还有另外两个文件db.sqllite3manage.py。

Let’s understand these files.

让我们了解这些文件。

manage.py (manage.py)

This is the file that we’ve used to run server. Basically that manage.py file help us to do some top level admin things. To see all the funtionality of that file other than running a server, just open terminal or command prompt and navigate to the directory where our manage.py file exists and run the command below.

这是我们用来运行服务器的文件。 基本上,manage.py文件可以帮助我们执行一些高级管理操作。 要查看除运行服务器以外该文件的所有功能,只需打开终端或命令提示符,然后导航到manage.py文件所在的目录,然后运行以下命令。

python3 manage.py help

python3 manage.py帮助

or

要么

python manage.py help  (if you have only python3 installed in your system)

python manage.py帮助 (如果您的系统中仅安装了python3 )

Now after running this command you can actually see all the things that our manage.py file can do like startapp, runserver, collectstatic. We’ll use many of these things later and we should never edit this file if you’re editing this file for specific reason, at that point you should be an expert django user before you go messing up with this file.

现在,运行此命令后,您实际上可以看到我们的manage.py文件可以执行的所有操作,例如startapp,runserver和collectstatic。 我们稍后将使用其中的许多功能,并且如果出于特定原因要编辑此文件,则永远不要编辑此文件,这时您应该成为django的专业用户,然后再弄乱该文件。

db.sqlite3 (db.sqlite3)

This file is a database that is generated for us whenever we make a new project and run the server. This is going to be a non-human readable file. It’s supposed to store data in a really efficient way.

该文件是一个在我们创建新项目并运行服务器时为我们生成的数据库。 这将是一个非人类可读的文件。 应该以一种非常有效的方式存储数据。

Now open my_website directory inside our project folder and you’ll see some other files and a directory as shown below.

现在打开项目文件夹中的my_website目录,您将看到其他文件和目录,如下所示。

Django Project Tour 2

__pycache_ (__pycache_)

This directory is going to be auto-generated everytime when we’re running the server. Inside __pycache_ there are some other files having extension .pyc. These are some internal files, we doesn’t need to worry about these at all.

每当我们运行服务器时,都会自动生成此目录。 在__pycache_内部,还有一些扩展名为.pyc的文件 这些是一些内部文件,我们完全不需要担心这些。

__init__.py (__init__.py)

This is also created automatically whenever we initially create a new project and we’ll never touch this file too because this file is not there for programmer’s use. It is there for some internal django working. We’re not going to worry about it too.

每当我们最初创建一个新项目时,它也会自动创建,并且我们永远也不会触摸此文件,因为该文件不存在供程序员使用。 它在那里有一些内部Django工作。 我们也不会为此担心。

settings.py (settings.py)

This is the file, that we’re going to use a lot. If we open this file using any text editor then you can see that there is a BASE_DIR variable that have the path of our base directory of our project.

这是文件,我们将大量使用。 如果我们使用任何文本编辑器打开此文件,则可以看到存在一个BASE_DIR变量,该变量具有项目基本目录的路径。

Django Project Tour 3

Next there is a SECRET_KEY that we should never show to anybody if we’re going to pushing up our project to internet. We can also change this key as we want to.

接下来是一个SECRET_KEY ,如果我们要将项目推向互联网,我们绝对不应该向任何人展示。 我们还可以根据需要更改此密钥。

Django Project Tour 4

Next is DEBUG, that is set as True. This is basically saying that you are working in a development environment on your computer. This helps us to show errors while running our project. When our project will be live on the internet, we’ll set DEBUG as False.

接下来是DEBUG ,将其设置为True。 基本上是说您正在计算机上的开发环境中工作。 这有助于我们在运行项目时显示错误。 当我们的项目将在互联网上发布时,我们将DEBUG设置为False。

Next two variables are ALLOWED_HOSTS and INSTALLED_APPS that we’ll see later when our project will be under production phase.

接下来的两个变量是ALLOWED_HOSTSINSTALLED_APPS ,我们稍后将在项目进入生产阶段时看到。

Next is MIDDLEWARE, This is also some advance stuff and auto-generated code by django.

接下来是MIDDLEWARE ,这也是django的一些高级知识和自动生成的代码。

Django Project Tour 5

Then there is a ROOT_URLCONF variable that’s basically saying where your initial URL file is.

然后有一个ROOT_URLCONF变量,它基本上是在说您的初始URL文件在哪里。

Django Project Tour 6

Next one is TEMPELATES, basically these tempelates helps to turning the python code into HTML, because when someone requests a website, it is going to give back HTML. As we can see when we open page source of any webpage, It gives us bunch of HTML Tags.

下一个是TEMPELATES ,基本上这些模板将有助于将python代码转换为HTML,因为当有人请求一个网站时,它将返回HTML。 正如我们看到的,当打开任何网页的页面源代码时,它为我们提供了一堆HTML标签。

Django Project Tour 7

Next is WSGI_APPLICATION, This is used when we’re hosting our project live, how people connect with it. We’ll see more when we publish our project live to the internet.

接下来是WSGI_APPLICATION ,当我们实时托管我们的项目时人们会用到它。 当我们将项目实时发布到互联网上时,我们会看到更多。

Django Project Tour 8

Next is DATABASES, This is the code that generated that file named as db.sqlite3 in our project directory. If we want to create another database file then we can also generate by editing this code.

接下来是DATABASES ,这是在我们的项目目录中生成名为db.sqlite3的文件的代码。 如果要创建另一个数据库文件,则还可以通过编辑此代码来生成。

Django Project Tour 9

Next is AUTH_PASSWORD_VALIDATORS, This basically saying that whenever someone makes a new user account what sort of things do we want to require of to get their passwords we’ll see it later too.

接下来是AUTH_PASSWORD_VALIDATORS ,这基本上是说,只要有人注册一个新用户帐户,我们需要什么样的东西才能获取密码,我们稍后也会看到。

Django Project Tour 10

Now other variables like LANGUAGE_CODE, TIME_ZONE are just there for making our website unique like what language code we want to use, by default it is US-English and what Time-zone we want to use.

现在,还有其他变量,例如LANGUAGE_CODETIME_ZONE ,用于使我们的网站具有独特性,例如我们要使用的语言代码,默认情况下是美国英语,以及我们要使用的时区。

urls.py (urls.py)

Anytime someone visits our website that is s connected to our django project. It’s going to come into this file and this file decides where the user’s requests should go next and what HTML is to sent back to user.

每当有人访问连接到django项目的我们的网站时。 该文件将进入该文件,该文件决定了下一步应将用户的请求发送到哪里以及将什么HTML发送回给用户。

Django Project Tour 11

wsgi.py (wsgi.py)

This file is for hosting our website so other people can access it, we’ll see this file when we upload our project to a server.

该文件用于托管我们的网站,以便其他人可以访问它,将项目上载到服务器时,我们会看到此文件。

Django Project Tour 12

So I hope you have understood that what the files inside our project folder are and what are the uses of those files.

因此,我希望您了解我们的项目文件夹中的文件是什么以及这些文件的用途。

If you have any confusion related to this tutorial, then please let us know in comments.

如果您对本教程有任何疑问,请在评论中告知我们。

翻译自: https://www.thecrazyprogrammer.com/2018/09/django-project-tour.html

django导包

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值