這篇文章主要介紹了通過mod_python配置運行在Apache上的Django框架,Django是最具人氣的Python web開發框架,需要的朋友可以參考下
為了配置基于 mod_python 的 Django,首先要安裝有可用的 mod_python 模塊的 Apache。 這通常意味著應該有一個 LoadModule 指令在 Apache 配置文件中。 它看起來就像是這樣:
- LoadModule python_module /usr/lib/apache2/modules/mod_python.so
Then, edit your Apache configuration file and add a
- <Location "/">
- SetHandler python-program
- PythonHandler django.core.handlers.modpython
- SetEnv DJANGO_SETTINGS_MODULE mysite.settings
- PythonDebug Off
- </Location>
要確保把 DJANGO_SETTINGS_MODULE 中的 mysite.settings 項目換成與你的站點相應的內容。
它告訴 Apache,任何在 / 這個路徑之后的 URL 都使用 Django 的 mod_python 來處理。 它 將 DJANGO_SETTINGS_MODULE 的值傳遞過去,使得 mod_python 知道這時應該使用哪個配置。
注意這里使用 ```` 指令而不是 ```` 。 后者用于指向你的文件系統中的一個位置,然而 ````
- System Message: WARNING/2 (<string>, line 403); backlink
- Inline literal start-string without end-string.
- System Message: WARNING/2 (<string>, line 403); backlink
- Inline literal start-string without end-string.
- System Message: WARNING/2 (<string>, line 403); backlink
- Inline literal start-string without end-string.
- System Message: WARNING/2 (<string>, line 403); backlink
- Inline literal start-string without end-string.
- System Message: ERROR/3 (<string>, line 405)
- Unexpected indentation.
指向一個 Web 站點的 URL 位置。 ````
- System Message: WARNING/2 (<string>, line 405); backlink
- Inline literal start-string without end-string.
- System Message: WARNING/2 (<string>, line 405); backlink
- Inline literal start-string without end-string.
Apache 可能不但會運行在你正常登錄的環境中,也會運行在其它不同的用戶環境中;也可能會有不同的文件路徑或 sys.path。 你需要告訴 mod_python 如何去尋找你的項目及 Django 的位置。
- PythonPath "['/path/to/project', '/path/to/django'] + sys.path"
注意,你應該在成品服務器上設置 PythonDebug Off 。如果你使用 PythonDebug On 的話,在程序產生錯誤時,你的用戶會看到難看的(并且是暴露的) Python 回溯信息。 如果你把 PythonDebug 置 On,當mod_python出現某些錯誤,你的用戶會看到丑陋的(也會暴露某些信息)Python的對錯誤的追蹤的信息。你也可以加入一些其它指令,比如 PythonAutoReload Off 以提升性能。 查看 mod_python 文檔獲得詳細的指令列表。
重啟 Apache 之后所有對你的站點的請求(或者是當你用了
新聞熱點
疑難解答