• <td id="ae6ms"><li id="ae6ms"></li></td>
  • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
  • <table id="ae6ms"></table>
  • <td id="ae6ms"></td>
    <td id="ae6ms"></td>
  • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
  • <td id="ae6ms"></td>
  • <table id="ae6ms"><li id="ae6ms"></li></table>
  • <table id="ae6ms"></table>
    西西軟件園多重安全檢測下載網站、值得信賴的軟件下載站!
    軟件
    軟件
    文章
    搜索

    首頁編程開發其它知識 → Windows 7中將Django部署到Apache Web Server

    Windows 7中將Django部署到Apache Web Server

    相關軟件相關文章發表評論 來源:西西整理時間:2014/3/7 22:07:54字體大?。?em class="fontsize">A-A+

    作者:西西點擊:229次評論:0次標簽: Python

    《派森》(Python)3.13 win32 英文安裝版
    • 類型:編程工具大?。?i>21M語言:英文 評分:8.7
    • 標簽:
    立即下載

    Django 提供了通用Web開發模式的高度抽象,提供了頻繁進行的編程作業的快速解決方法,以及為“如何解決問題”提供了清晰明了的約定。同時,Django 嘗試留下一些方法,來讓你根據需要在framework之外來開發。

    本質上來說, Django 只不過是用 Python 編寫的一組類庫。用 Django 開發站點就是使用這些類庫編寫 Python 代碼。因此,學習 Django 的關鍵就是學習如何進行 Python 編程并理解 Django 類庫的運作方式。

    如果你有Python開發經驗,在學習過程中應該不會有任何問題,基本上,Django的代碼并 沒有使用一些黑色魔法(例如代碼中的欺騙行為,某個實現解釋或者理解起來十分困難)。 對你來說,學習Django就是學習她的命名規則和API。

    配置思路

    1、配置apache的httpd.conf文件

    2、配置django相關配置文件

    配置過程

    其實配置生效針對不同的環境有不同的細節需要處理,網上的方案(包括本篇)都不是一定通用的,只是在某種環境下有效,但總體思路就是配置上述提及的兩個配置文件。

    部署django項目常用的兩個方式是使用mod_python和mod_wsgi兩種部署方式,這里我使用的是mod_wsgi。

    1、先去網上下載個名叫這個的東西:mod_wsgi-3.4.ap22.win32-py2.7,里面有個文件是mod_wsgi.so,然后把這個copy到apache安裝目錄的modules文件下(默認安裝目錄是:C:\Program Files (x86)\Apache Software Foundation\Apache2.2\modules)

    下面兩個配置中涉及路徑的很容易搞錯,如果是絕對路徑的話要檢查自己是否正確。

    2、在Django項目更目錄下新建兩個文件:

    django.wsgi:

    #coding=utf-8

    import os

    import sys

    import django.core.handlers.wsgi

    os.environ['DJANGO_SETTINGS_MODULE'] = 'appops.settings'

    app_apth = "D:/OPSAPP/appops"

    sys.path.append(app_apth)

    application = django.core.handlers.wsgi.WSGIHandler()

    apache_django_wsgi.conf:

    #Alias / D:/OPSAPP/appops

    Alias /favicon.jpg D:/OPSAPP/appops/static/images/favicon.jpg

    #WSGIScriptAlias /api "D:/OPSAPP/appops/appapi/handler.py"  #注意,這里在httpd.conf中寫過的話這里就不用寫了。

    WSGIScriptAlias / "D:/OPSAPP/django.wsgi"

    WSGIPassAuthorization On

    <Directory "D:/OPSAPP/appops/appops">

    Order Deny,Allow

    Allow from all

    </Directory>

    Alias /static/ D:/OPSAPP/appops/static/

    <Directory  D:/OPSAPP/appops/static/ >

    Order deny,allow

    Allow from all

    IndexOptions FancyIndexing

    </Directory>

    <Directory  D:/OPSAPP/appops/ >

    Order deny,allow

    Allow from all

    IndexOptions FancyIndexing

    </Directory>

    <Directory "D:/OPSAPP"> 

    Allow from all

    </Directory>

    目錄結構如下:

    3、編輯apache的配置文件httpd.conf(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf)

    中間加上一句:

    LoadModule wsgi_module modules/mod_wsgi.so

    文件結尾新增下列配置:

    Alias /static D:/OPSAPP/appops/static     #這是為了可以通過url來訪問static文件

    <Location "/static/">

           SetHandler None

    </Location><br>

     

    <VirtualHost *:80>                       #配置虛擬目錄

    ServerName app.ops.test.com

    #ServerName 192.168.18.74

     

    DocumentRoot D:/OPSAPP

    WSGIScriptAlias / D:/OPSAPP/django.wsgi

     

    <Directory />

    Order deny,allow

    Allow from all

    </Directory>

    <Directory /apache>

    Allow from all

    </Directory>

    </VirtualHost>

     

    <Directory "D:/OPSAPP/appops/static/">    #這個一定需要,不然網頁樣式錯誤,css沒有起作用

    Order Deny,Allow

    Allow from all

    </Directory>

    重啟下apache服務基本就OK了。

    常見錯誤

    訪問失敗時的錯誤會記錄在apache日志里(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\logs),

    1、靜態資源不能訪問,如css樣式錯亂等,需要在httpd.conf文件里增加配置:

    <Directory  D:/OPSAPP/appops/static/ >

    Order deny,allow

    Allow from all

    IndexOptions FancyIndexing

    </Directory>

    2、出現找不到模塊的錯,如no module named XXX等,主要有兩個原因:

    1)、路徑錯了

    2)、文件命名跟Django或python內部模塊沖突了

      相關評論

      閱讀本文后您有什么感想? 已有人給出評價!

      • 8 喜歡喜歡
      • 3 頂
      • 1 難過難過
      • 5 囧
      • 3 圍觀圍觀
      • 2 無聊無聊

      熱門評論

      最新評論

      發表評論 查看所有評論(0)

      昵稱:
      表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
      字數: 0/500 (您的評論需要經過審核才能顯示)
      女人让男人桶30分钟免费视频,女人张开腿让男人桶个爽,一进一出又大又粗爽视频
    • <td id="ae6ms"><li id="ae6ms"></li></td>
    • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
    • <table id="ae6ms"></table>
    • <td id="ae6ms"></td>
      <td id="ae6ms"></td>
    • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
    • <td id="ae6ms"></td>
    • <table id="ae6ms"><li id="ae6ms"></li></table>
    • <table id="ae6ms"></table>