Django筆記——Eclipse+pydev首個django例子helloworld

來源:互聯網
上載者:User

第一個django程式:

1.      安裝Python2.x,建議安裝2.6或2.7  下載地址www.python.org

配置環境變數     我的電腦->屬性->進階->環境變數->系統變數

增加PYTHON_HOME     C:\Python27

修改Path  加入%PYTHON_HOME%

2.      安裝django 下載地址https://www.djangoproject.com/

當前為1.3.1,將下載檔案解壓後放到你想放的位置

開始-運行-cmd   切換到解壓檔案放的位置

執行:setup.py install

 

安裝完後把%PYTHON_HOME%\Scripts加到PATH中去,因為該路徑下面的django-admin.py後面會用到

 

3.      建立項目:

開始-運行-cmd  切換到工作空間

產生項目

django-admin.py startproject hello

得到hello檔案夾下四個檔案

__init__.py 表示這是一個python包,裡面沒有內容 
manage.py 提供簡單化的django-admin.py命令 
settings.py 設定檔 
urls.py      url對應檔

 

此時可以啟動服務

manage.py runserver

 

可以訪問: http://localhost:8000/

頁面如下:

 

 

4.      用pydev編輯項目,實現第一個helloworld

Pydev外掛程式安裝並配置完後,開啟eclipse

File – New – Pydev Project

輸入項目名稱

取消掉Use Default,自己選擇目錄為第三步建立的目錄

 

增加原始碼檔案夾:

點擊項目,右鍵,properties

Pydev-PYTHONPATH  Source Floders選項卡  Add source floder

將當前專案檔夾加入

 

在src下建立一個first.py檔案

內容如下

fromdjango.http importHttpResponse

 

 

defhello(request):

   returnHttpResponse("Hello world! First Django")

 

修改urls.py,增加

(r'^first$', 'first.hello'),

 

選中manage.py-右鍵– Run As – Run Configurations

加入運行參數  (x) = Arguments選項卡

runserver –noreload

 

 

之後,就可以在eclipse直接啟動服務

 

選擇manage.py,右鍵 Python Run

 

訪問:

http://localhost:8000/first


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.