簡介
本教學將引導您使用 Django 和 Django REST Framework (DRF) 建立基本的 Web 應用程式。 該應用程式將管理圖書收藏,透過 REST API 啟用 CRUD(建立、讀取、更新、刪除)操作。
先決條件
- Python 3.8 或更高版本。
- Python 和 Django 的基礎。
- pip(Python 套件安裝程式)。
- 熟悉虛擬環境設定(例如,
venv
)。
第 1 步:環境設定
建議的虛擬機器配置:
- 記憶體: 8 GB
- 處理器: 4 核心(8 執行緒)
- 儲存空間: 100 GB
- 網路:橋接網路(用於唯一的 IP)或 NAT(用於透過主機存取網際網路)。
虛擬機器設定:
- 從可靠來源(例如 Ubuntu 官方網站)下載
ubuntu-22.04-server-cloudimg-amd64.ova
映像。 - 開啟 VMware Workstation、Fusion 或 ESXi 並匯入 OVA 檔案。請按照螢幕上的指示進行操作。
- 為您的虛擬機器命名(例如,
TMS_VM
)。 - 根據上述建議配置虛擬機器的記憶體、處理器、硬碟和網路設定。
Ubuntu 22.04 伺服器設定:
-
啟動虛擬機器。
-
登入並更新系統:
sudo apt update && sudo apt upgrade -y
-
安裝必要工具:
sudo apt install git python3 python3.10-venv python3-pip python3-venv git build-essential -y
-
建立使用者:以下指令建立一個名為
django
並具有適當權限的使用者。 請記得將"your_email@example.com"
替換為您的實際電子郵件地址。sudo groupadd bulletproof sudo adduser django sudo usermod -aG bulletproof django
-
建立專案目錄:
mkdir /home/django/projects
-
調整群組擁有權與權限:
sudo chown :bulletproof /home/django/projects sudo chmod 775 /home/django/projects sudo usermod -d /home/django/projects django sudo chown django:bulletproof /home/django/projects su - django
VS 程式碼設定(遠端 SSH):
在 VS Code 中安裝 Python、Pylance、Flake8、Black 和 Django 擴充功能。 確保使用 pip 在虛擬機器上安裝了 Flake8 和 Black。配置 VS Code 以使用虛擬環境的 Python 解釋器並啟用 linting 和格式化。 建立 pyproject.toml
和 .flake8
檔案進行設定(請參閱原始文件中的範例)。
Python 設定:
-
建立虛擬環境:
mkdir tms && cd tms python3 -m venv .venv source .venv/bin/activate # (env\Scripts\activate on Windows)
-
安裝 Django 和 DRF:
pip install django djangorestframework
-
建立 Django 專案:
django-admin startproject tms .
-
運行開發伺服器:
python manage.py runserver 0.0.0.0:8000
如果遇到
DisallowedHost
錯誤,請將伺服器的 IP 位址加入到ALLOWED_HOSTS
中的settings.py
。
Git 儲存庫設定:
- 建立
README.md
、requirements.txt
(使用pip freeze > requirements.txt
)、LICENSE
和.gitignore
檔案。 - 產生 SSH 金鑰:
ssh-keygen -t ed25519 -C "your_email@example.com"
。將公鑰新增至您的 GitHub 帳戶。 - 初始化 Git 儲存庫:
git init
- 新增遠端儲存庫:
git remote add origin git@github.com:username/repository.git
- 提交並推送您的變更:
git add .
、git commit -m "Initial commit"
、git push -u origin main
虛擬機器快照:
在初始設定後使用 VMware 的快照功能建立虛擬機器的快照。 將其命名為描述性名稱,例如“InitialSetup”。
以上是用於 TMS 專案的 Bulletproof Django API的詳細內容。更多資訊請關注PHP中文網其他相關文章!

ArraySareAryallyMoremory-Moremory-forigationDataDatueTotheIrfixed-SizenatureAntatureAntatureAndirectMemoryAccess.1)arraysStorelelementsInAcontiguxufulock,ReducingOveringOverheadHeadefromenterSormetormetAdata.2)列表,通常

ToconvertaPythonlisttoanarray,usethearraymodule:1)Importthearraymodule,2)Createalist,3)Usearray(typecode,list)toconvertit,specifyingthetypecodelike'i'forintegers.Thisconversionoptimizesmemoryusageforhomogeneousdata,enhancingperformanceinnumericalcomp

Python列表可以存儲不同類型的數據。示例列表包含整數、字符串、浮點數、布爾值、嵌套列表和字典。列表的靈活性在數據處理和原型設計中很有價值,但需謹慎使用以確保代碼的可讀性和可維護性。

Pythondoesnothavebuilt-inarrays;usethearraymoduleformemory-efficienthomogeneousdatastorage,whilelistsareversatileformixeddatatypes.Arraysareefficientforlargedatasetsofthesametype,whereaslistsofferflexibilityandareeasiertouseformixedorsmallerdatasets.

theSostCommonlyusedModuleForCreatingArraysInpyThonisnumpy.1)NumpyProvidEseffitedToolsForarrayOperations,Idealfornumericaldata.2)arraysCanbeCreatedDusingsnp.Array()for1dand2Structures.3)

toAppendElementStoApythonList,usetheappend()方法forsingleements,Extend()formultiplelements,andinsert()forspecificpositions.1)useeAppend()foraddingoneOnelementAttheend.2)useextendTheEnd.2)useextendexendExendEnd(

TocreateaPythonlist,usesquarebrackets[]andseparateitemswithcommas.1)Listsaredynamicandcanholdmixeddatatypes.2)Useappend(),remove(),andslicingformanipulation.3)Listcomprehensionsareefficientforcreatinglists.4)Becautiouswithlistreferences;usecopy()orsl

金融、科研、医疗和AI等领域中,高效存储和处理数值数据至关重要。1)在金融中,使用内存映射文件和NumPy库可显著提升数据处理速度。2)科研领域,HDF5文件优化数据存储和检索。3)医疗中,数据库优化技术如索引和分区提高数据查询性能。4)AI中,数据分片和分布式训练加速模型训练。通过选择适当的工具和技术,并权衡存储与处理速度之间的trade-off,可以显著提升系统性能和可扩展性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

記事本++7.3.1
好用且免費的程式碼編輯器

Dreamweaver Mac版
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!