為了配置基于 mod_python 的 Django,首先要安裝有可用的 mod_python 模塊的 Apache。 這通常意味著應(yīng)該有一個(gè) LoadModule 指令在 Apache 配置文件中。 它看起來(lái)就像是這樣:
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 項(xiàng)目換成與你的站點(diǎn)相應(yīng)的內(nèi)容。
它告訴 Apache,任何在 / 這個(gè)路徑之后的 URL 都使用 Django 的 mod_python 來(lái)處理。 它 將 DJANGO_SETTINGS_MODULE 的值傳遞過(guò)去,使得 mod_python 知道這時(shí)應(yīng)該使用哪個(gè)配置。
注意這里使用 ```` 指令而不是 ```` 。 后者用于指向你的文件系統(tǒng)中的一個(gè)位置,然而 ````
System Message: WARNING/2 (<string>, line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (<string>, line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (<string>, line 403); backlinkInline literal start-string without end-string.System Message: WARNING/2 (<string>, line 403); backlinkInline literal start-string without end-string.System Message: ERROR/3 (<string>, line 405)Unexpected indentation.
指向一個(gè) Web 站點(diǎn)的 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ì)運(yùn)行在你正常登錄的環(huán)境中,也會(huì)運(yùn)行在其它不同的用戶環(huán)境中;也可能會(huì)有不同的文件路徑或 sys.path。 你需要告訴 mod_python 如何去尋找你的項(xiàng)目及 Django 的位置。
PythonPath "['/path/to/project', '/path/to/django'] + sys.path"
你也可以加入一些其它指令,比如 PythonAutoReload Off 以提升性能。 查看 mod_python 文檔獲得詳細(xì)的指令列表。
注意,你應(yīng)該在成品服務(wù)器上設(shè)置 PythonDebug Off 。如果你使用 PythonDebug On 的話,在程序產(chǎn)生錯(cuò)誤時(shí),你的用戶會(huì)看到難看的(并且是暴露的) Python 回溯信息。 如果你把 PythonDebug 置 On,當(dāng)mod_python出現(xiàn)某些錯(cuò)誤,你的用戶會(huì)看到丑陋的(也會(huì)暴露某些信息)Python的對(duì)錯(cuò)誤的追蹤的信息。
重啟 Apache 之后所有對(duì)你的站點(diǎn)的請(qǐng)求(或者是當(dāng)你用了 <VirtualHost> 指令后則是虛擬主機(jī))都會(huì)由 Djanog 來(lái)處理。
新聞熱點(diǎn)
疑難解答
圖片精選