django模型_Django模型

django模型

In this tutorial, we’ll get into the details of Django Models. Before we do that, let’s quickly set up our Django Project from the terminal.

在本教程中,我们将详细介绍Django模型。 在此之前,让我们从终端快速设置我们的Django项目。

Execute the following commands one by one:

一一执行以下命令:

mkdir JournaldevDjangoModels
cd JournalDevDjangoModels
virtualenv -p /usr/local/bin/python3 env
source env/bin/activate
pip3 install django
django-admin startproject DjangoModel
python3 manage.py runserver
django-admin startapp school

Once we’ve created the school app, we need to add it in the INSTALLED_APPS inside the settings.py

创建学校应用后,我们需要将其添加到settings.py中的INSTALLED_APPS settings.py

Take note of the models.py file that’s created in the school app. It’ll be the Most Wanted file in this tutorial. Let’s get started.

记下在学校应用程序中创建的models.py文件。 这将是本教程中最想要的文件。 让我们开始吧。

Django模型 (Django Models)

The database is an important part of any web application. Django Models are a source of information for your data. You can store values in the form of fields in it.

数据库是任何Web应用程序的重要组成部分。 Django模型是数据信息的来源。 您可以在其中以字段形式存储值。

Each Django Model would be held in the database and the fields defined in the Django Models are database fields.

每个Django模型都将保存在数据库中,并且Django模型中定义的字段是数据库字段。

Django Models are used to execute SQL code behind the scene as well.

Django模型也用于在后台执行SQL代码。

Let’s create our first Django Model in the models.py file.

让我们在models.py文件中创建第一个Django模型。

Django模型范例 (Django Model Example)

Following is the code from the models.py file:

以下是来自models.py文件的代码:

from django.db import models

# Create your models here.
class Student(models.Model):
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    email = models.EmailField()
    website = models.URLField()

Student is a Django Model with four fields.

Student是具有四个字段的Django模型。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值