我一直在將我的Django項目遷移到生產服務器。這是情況。 我的最終結果頁面(HTML源代碼)看起來是這樣的:將Django遷移到生產服務器
Number of exponentials: 1 <br /><br />
Function: 98.919106*2.71828182845905**(-0.014026249*t) <br /><br />
Parameters of exponentials: {'a': [98.919105999999999], 'k': [0.014026248999999999], 'c': [0]} <br /><br />
Non physical solution: False <br /><br />
<img src="plots/data_2e_03.png" alt="some_text"/>
這是從我的Django應用程序的數據填充的模板。模板看起來像:
Number of exponentials: {{rp.user_choice.number_of_exponentials}} <br /><br />
Function: {{rp.user_choice.function}} <br /><br />
Parameters of exponentials: {{rp.user_choice.parameters_of_exponentials}} <br /><br />
Non physical solution: {{rp.user_choice.non_physical_solution}} <br /><br />
<img src="plots/{{rp.input_file_name}}.png" alt="some_text"/>
問題是圖像不顯示。只有alt被打印出來。當我檢查html源代碼(粘貼在上面)時,它顯示了plots/data_2e_03.png作爲鏈接(是的,在HTML源代碼中)。當我點擊它時,帶我到另一頁的來源。
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
[no address given] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.16 (Debian) Server at bioinformatika.djangoserver Port 80</address>
</body></html>
這裏是我的Apache的網站配置:
<VirtualHost *:80>
ServerName bioinformatika.djangoserver
DocumentRoot /home/user/bioinformatika/Server/bioinformatika/apache
Alias /plots/ /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots/
<Directory /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots>
Order deny,allow
Allow from all
</Directory>
<Directory /home/user/bioinformatika/Server/bioinformatika/apache>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess bioinformatika.djangoserver processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup bioinformatika.djangoserver
WSGIScriptAlias//home/user/bioinformatika/Server/bioinformatika/apache/django.wsgi
爲了讓Apache的處理我的媒體文件的目的,我添加了:
Alias /plots/ /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots/
<Directory /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots>
Order deny,allow
Allow from all
</Directory>
其他部分有關設置Apache的, mod_wsgi和Django,並正在工作。
一旦我刪除Django settings.py中的調試。顯示其源的頁面(帶有內部服務器錯誤)現在已呈現並顯示在瀏覽器中。 /etc/log/apache2/error.log給出以下:
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] return callback(request, **param_dict)
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] File "/home/user/bioinformatika/virtual_bio/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/utils/decorators.py", line 91, in _wrapped_view
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] response = view_func(request, *args, **kwargs)
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] File "/home/user/bioinformatika/virtual_bio/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/views/defaults.py", line 32, in server_error
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] t = loader.get_template(template_name) # You need to create a 500.html template.
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] File "/home/user/bioinformatika/virtual_bio/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/template/loader.py", line 145, in get_template
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] template, origin = find_template(template_name)
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] File "/home/user/bioinformatika/virtual_bio/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/template/loader.py", line 138, in find_template
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] raise TemplateDoesNotExist(name)
[Sun Jun 24 11:22:15 2012] [error] [client 192.168.0.14] TemplateDoesNotExist: 500.html
任何建議表示讚賞。我在想奇怪的行爲可能與我的服務器設置有關,而且我的結果不是默認的,容易解決的問題,如果是這種情況,我將不勝感激,如果有人可以請檢查我的Apache配置是否正確。
UPDATE:
這是我錯過配置的路徑的問題。 STATIC_URL,STATIC_ROOT,MEDIA_URL和MEDIA_ROOT的含義對我而言並不清楚,這導致了我無法完全診斷的部署問題中的問題。
但是,避免它的方法是對開發和生產服務器上的文件如何提供工作概念性知識。