日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

Django的開發(fā)步驟原來是這樣的_python

作者:now?~?try ? 更新時間: 2022-04-19 編程語言

Django 是一個開放源代碼的 Web 應(yīng)用框架,由 Python 寫成。

開發(fā)步驟如下:

1.?安裝Django

pip install django

2.?創(chuàng)建django項目

django-admin startproject mysite

也可以使用pycharm創(chuàng)建,如果使用Pycharm創(chuàng)建,記得刪除setting.py里面的DIRS templates。

在這里插入圖片描述

3.?創(chuàng)建并注冊app

python manage.py startapp app01

在這里插入圖片描述

若不執(zhí)行步驟3,在app下的models.py寫類時,無法在數(shù)據(jù)庫中創(chuàng)建表。

4.?配置靜態(tài)文件路徑和模板的路徑

5.?配置數(shù)據(jù)庫相關(guān)操作

(1)安裝第三方庫

pip install mysqlclient

(2)去MySQL創(chuàng)建一個數(shù)據(jù)庫

(3)配置數(shù)據(jù)庫中的setting.py文件。

在這里插入圖片描述

(4)在app下的models.py中編寫代碼創(chuàng)建表

在這里插入圖片描述

(5)執(zhí)行兩個命令,可以通過models.py中的類來創(chuàng)建數(shù)據(jù)庫中對應(yīng)的表。

python manage.py makemigrationspython manage.py migrate

6.在urls.py,路由,創(chuàng)建url和視圖函數(shù)的關(guān)系

在這里插入圖片描述

7.在views.py,視圖函數(shù)中,編寫業(yè)務(wù)邏輯

在這里插入圖片描述

8.在templates目錄,編寫HTML模板

在這里插入圖片描述

總結(jié)

原文鏈接:https://blog.csdn.net/weixin_43765321/article/details/122915206

欄目分類
最近更新