1

Django プロジェクトを実稼働サーバーに移行することに行き詰まっています。これが状況です。最終結果ページ (HTML ソース) は次のようになります。

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

問題は、画像が表示されないことです。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

アドバイスをいただければ幸いです。奇妙な動作は私のサーバー設定に関係している可能性があると考えています.デフォルトで簡単に解決できる問題ではないことが判明しました.

アップデート:

構成されたパスの問題がありませんでした。STATIC_URL、STATIC_ROOT、MEDIA_URL、および MEDIA_ROOT の意味がよくわからなかったので、展開に関する質問で完全に診断できなかった問題が発生しました。

ただし、これを回避する方法は、開発サーバーと運用サーバーでファイルがどのように提供されるかについて、実際に使用できる概念的な知識を持つことです。

4

1 に答える 1

4

projectname/templates フォルダーに、サーバーが非 DEBUG モードで表示されるように、500.html というファイルを作成する必要があります。(同様の目的で 404.html ファイルを作成する必要があります)。

また、設定を確認する必要があります。TEMPLATE_DIRSには、サーバー上のプロジェクト名/テンプレートフォルダーへの絶対パスが含まれています。

于 2012-06-24T17:30:47.080 に答える