我一直在将我的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的含义对我而言并不清楚,这导致了我无法完全诊断的部署问题中的问题。
但是,避免它的方法是对开发和生产服务器上的文件如何提供工作概念性知识。