標籤:scripts 最好 安裝完成 互動式 identify 技術分享 iter bsd doc
Django是一個python類庫,使用前必須安裝好python。推薦使用Python3,支援python2.7的最新Django版本為1.11LTS.
一、安裝方式:
使用pip命令安裝。
pip install Django==2.1 (此命令可以指定安裝版本)
pip install Django (此命令安裝最新版本)
使用pip卸載舊的版本
How to get Django
Django is available open-source under the BSD license. We recommend using the latest version of Python 3. The last version to support Python 2.7 is Django 1.11 LTS. See the FAQ for the Python versions supported by each version of Django. Here’s how to get it:
Option 1: Get the latest official version
The latest official version is 2.1. Read the 2.1 release notes, then install it with pip:
pip install Django==2.1
Option 2: Get the latest development version
The latest and greatest Django version is the one that’s in our Git repository (our revision-control system). This is only for experienced users who want to try incoming changes and help identify bugs before an official release. Get it using this shell command, which requires Git:
git clone https://github.com/django/django.git
You can also download a gzipped tarball of the development version. This archive is updated every time we commit code.
一、安裝Django1. 通過pip安裝Django
如果你是通過升級的方式安裝Django,那麼你需要先卸載舊的版本。
Django提供3種發行版本,推薦使用官方的穩定版本:
- 你的作業系統提供的發行版本(Linux)
- 官方穩定版本(推薦)
- 開發測試版本
Django本質上是Python語言的一個類庫,因此可以通過pip工具安裝。這也是最簡便最好的安裝方式。不建議通過下載安裝包或者編譯源碼進行安裝的方法,除非你的環境無法串連外部網路。
這裡介紹windows系統下pip命令安裝方式。
win+r,調出cmd,運行命令:pip install django
,自動安裝PyPi提供的最新版本。
如果要指定版本,可使用pip install django==1.10
這種形式。
安裝完成後如所示:
如果你看到本教程的時候,Django的版本已經發生了很大的變化,那麼你可能需要注意一些版本之間的不同之處,最好的辦法,就是指定安裝與教程一樣的1.11.6
版本。
在Linux作業系統中,也是一樣,使用pip工具包安裝Django。
2. 驗證安裝
進入Python互動式環境(注意一定要進入剛才安裝了Django的Python解譯器),按下面所示查看安裝版本:
>>> import django>>> print(django.get_version())1.11
We’ll assume you have Django installed already. You can tell Django is installed and which version by running the following command in a shell prompt (indicated by the $ prefix):
?/? ?
$ python -m django --version
或者使用pip list
命令,查看是否存在Django模組。
3. 配置系統內容
成功安裝Django後,以windows為例,在Python根目錄下的Scripts目錄中可找到一個django-admin.exe
檔案,這是Django的核心管理程式,最好將它加入作業系統的環境變數中,這樣在以後的調用會比較方便。
如何進入環境變數設定介面,參考Python教程中的相關部分。如所示,在Path變數中添加Scripts目錄。
回到cmd介面,運行django-admin help
,能看到下面的內容表示環境變數設定成功。
Python開發之Django架構入門(1)Django安裝