Reputation: 16329
I'm stuck with migrating my Django project to a production server. Here is the situation. My final result page (HTML source) looks something like this:
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"/>
It is a template populated by data from my Django app. The template looks like:
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"/>
The problem is that the image isn't showing. Only the alt is printed out. When i check the html source (pasted above) it shows plots/data_2e_03.png as a link (yes, in the HTML source). When i click on it takes me to another page's source.
<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>
Here is my apache site configuration:
<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
For the purpose of letting apache handle my media files, i added the:
Alias /plots/ /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots/
<Directory /home/user/bioinformatika/Server/bioinformatika/bioinformatika/plots>
Order deny,allow
Allow from all
</Directory>
Other parts are about setting apache, mod_wsgi and Django, and are working.
Once i remove the Debug in Django settings.py. The page (with Internal server error) whose source was shown is now rendered and showed in the browser. /etc/log/apache2/error.log gives the following:
[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
Any advice is appreciated. I'm thinking the odd behavior could have something to do with my server settings, and my turn out not to be default, easy solvable problem, if that is the case I would appreciate if someone could please check if my apache configuration is correct.
UPDATE:
It was i miss configured paths problem. The meaning of STATIC_URL, STATIC_ROOT, MEDIA_URL, and MEDIA_ROOT were unclear to me which yielded the problem in the question on deployment which i couldn't fully diagnose.
However, the way to avoid it is to have a working conceptual knowledge of how files are served on a development and production server.
Upvotes: 1
Views: 901
Reputation: 27311
In your projectname/templates folder you need to create a file called 500.html for the server to display when in non-DEBUG mode. (you should create a 404.html file for a similar purpose).
You also need to make sure settings.TEMPLATE_DIRS includes the absolute path to your projectname/templates folder.. on the server.
Upvotes: 4