通過mod_python配置運行在Apache上的Django框架
為了配置基于 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> directive that ties a specific URL path to a specific Django installation. 例如:
<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 知道這時應該使用哪個配置。
注意這里使用 ```` 指令而不是 ```` 。 后者用于指向你的文件系統(tǒng)中的一個位置,然而 ````
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 可能不但會運行在你正常登錄的環(huán)境中,也會運行在其它不同的用戶環(huán)境中;也可能會有不同的文件路徑或 sys.path。 你需要告訴 mod_python 如何去尋找你的項目及 Django 的位置。
PythonPath "['/path/to/project', '/path/to/django'] + sys.path"
你也可以加入一些其它指令,比如 PythonAutoReload Off 以提升性能。 查看 mod_python 文檔獲得詳細的指令列表。
注意,你應該在成品服務器上設置 PythonDebug Off 。如果你使用 PythonDebug On 的話,在程序產(chǎn)生錯誤時,你的用戶會看到難看的(并且是暴露的) Python 回溯信息。 如果你把 PythonDebug 置 On,當mod_python出現(xiàn)某些錯誤,你的用戶會看到丑陋的(也會暴露某些信息)Python的對錯誤的追蹤的信息。
重啟 Apache 之后所有對你的站點的請求(或者是當你用了 <VirtualHost> 指令后則是虛擬主機)都會由 Djanog 來處理。
相關文章
Django動態(tài)展示Pyecharts圖表數(shù)據(jù)的幾種方法
本文主要介紹了Django動態(tài)展示Pyecharts圖表數(shù)據(jù)的幾種方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-08-08