亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

python第三方庫之Django學習筆記二

Java3y / 3171人閱讀

摘要:上一節(jié)項目框架已經搭建完畢,現(xiàn)在開始連接數據庫,創(chuàng)建數據庫設置默認安裝了數據庫打開文件數據庫引擎數據庫的名字小貼士如果你選擇,數據庫是以文件的形式生成,要設置成絕對路徑創(chuàng)建表結構創(chuàng)建模型激活模型執(zhí)行命令執(zhí)行成功后目錄結構如下圖

上一節(jié)項目框架已經搭建完畢,現(xiàn)在開始連接數據庫,創(chuàng)建model

1、數據庫設置
python默認安裝了sqlite數據庫

打開文件:dayang/settings.py

ENGINE – 數據庫引擎

     "django.db.backends.sqlite3", 
     "django.db.backends.postgresql", 
     "django.db.backends.mysql",
     "django.db.backends.oracle".

NAME – 數據庫的名字

小貼士:如果你選擇sqlite,數據庫是以文件的形式生成,name要設置成絕對路徑

By default, INSTALLED_APPS contains the following apps, all of which come with Django:

django.contrib.admin – The admin site. You’ll use it shortly.

django.contrib.auth – An authentication system.

django.contrib.contenttypes – A framework for content types.

django.contrib.sessions – A session framework.

django.contrib.messages – A messaging framework.

django.contrib.staticfiles – A framework for managing static files.

These applications are included by default as a convenience for the common case.

Some of these applications make use of at least one database table, though, so we need to create the tables in the database before we can use them. To do that, run the following command:
manage.py migrate # 創(chuàng)建表結構

2、創(chuàng)建模型

3、激活模型
That small bit of model code gives Django a lot of information. With it, Django is able to:

Create a database schema (CREATE TABLE statements) for this app.
Create a Python database-access API for accessing Question and Choice objects.
But first we need to tell our project that the polls app is installed.

執(zhí)行命令:manage.py makemigrations polls
# By running makemigrations, you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration.

執(zhí)行成功后目錄結構如下圖:

Now, run migrate again to create those model tables in your database:

remember the three-step guide to making model changes:

Change your models (in models.py).
Run python manage.py makemigrations to create migrations for those changes
Run python manage.py migrate to apply those changes to the database.

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://www.ezyhdfw.cn/yun/40791.html

相關文章

  • python三方庫之Django學習筆記

    摘要:一個空文件,告訴該目錄是一個包。運行項目切換到目錄執(zhí)行命令瀏覽器輸入看到以下界面運行成功小貼士修改端口命令創(chuàng)建切換到同級目錄,執(zhí)行命令現(xiàn)在的結構目錄如下編寫你的第一個視圖新建文件運行命令查看運行結果 1、安裝Django pip install Django 2、版本號查詢 python -m django --version showImg(https://segmentfa...

    canger 評論0 收藏0
  • 保姆級教程帶你開發(fā)優(yōu)質的Python庫之上篇【建議收藏】

    摘要:正式的專欄第篇,同學站住,別錯過這個從開始的文章前面學委的入門到精通專欄積累了篇文章,當然學委博客還有幾十篇應用的文章。 正式的Python專欄第9篇,同學站住...

    hyuan 評論0 收藏0
  • django rest framework個人學習筆記)————Quickstart

    摘要:我們將會創(chuàng)建一個簡單的,來讓管理員能夠查看和編輯和。我們將會在接下來的例子中使用這個賬戶。創(chuàng)建一個新的模塊叫。但是是一個好的設計。最后,我們使用來導入默認的登錄登出這是可選的。我們想啟用分頁和只有用戶能夠調用。 Quickstart 我們將會創(chuàng)建一個簡單的API,來讓管理員能夠查看和編輯Users和Groups。 項目開始 創(chuàng)建一個新的項目叫 tutorial,然后創(chuàng)建一個app叫qu...

    gghyoo 評論0 收藏0
  • django rest framework個人學習筆記)————Quickstart

    摘要:我們將會創(chuàng)建一個簡單的,來讓管理員能夠查看和編輯和。我們將會在接下來的例子中使用這個賬戶。創(chuàng)建一個新的模塊叫。但是是一個好的設計。最后,我們使用來導入默認的登錄登出這是可選的。我們想啟用分頁和只有用戶能夠調用。 Quickstart 我們將會創(chuàng)建一個簡單的API,來讓管理員能夠查看和編輯Users和Groups。 項目開始 創(chuàng)建一個新的項目叫 tutorial,然后創(chuàng)建一個app叫qu...

    JiaXinYi 評論0 收藏0

發(fā)表評論

0條評論

Java3y

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<