2012-06-24 2 views
1

Я застрял в переносе моего проекта Django на производственный сервер. Вот ситуация. Моя последняя страница результатов (источник HTML) выглядит примерно так:Перенос Django на рабочий сервер

Number of exponentials: 1 <br /><br /> 
Function: 98.919106*2.71828182845905**(-0.014026249*t) <br /><br /> 
Parameters of exponentials: {&#39;a&#39;: [98.919105999999999], &#39;k&#39;: [0.014026248999999999], &#39;c&#39;: [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"/> 

Проблема в том, что изображение не отображается. Распечатывается только альт. Когда я проверяю источник html (вставленный выше), он показывает графики/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> 

Вот мой апач конфигурация сайта:

<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> 

Другие детали о настройке апача, mod_wsgi и Django, и работают.

Как только я удалю Debug в 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 для меня было непонятно, что привело к проблеме в вопросе развертывания, которую я не мог полностью диагностировать.

Однако, чтобы избежать этого, необходимо иметь концептуальное представление о том, как файлы обслуживаются на сервере разработки и производства.

ответ

4

В папке projectname/templates вам необходимо создать файл с именем 500.html для отображения сервера в режиме, отличном от DEBUG. (вы должны создать файл 404.html для аналогичной цели).

Вам также необходимо убедиться, что settings.TEMPLATE_DIRS содержит абсолютный путь к вашей папке projectname/templates .. на сервере.

Смежные вопросы