1

I have a Django application and it is serving a static SVG file (I point my browser directly to something like: http://myserver.com/static/my.svg). I am using the built-in webserver that comes with Django. I have run this application from an Ubuntu server and it has worked fine. When I say "worked fine", I mean that the svg file is displayed directly on the browser window (for both Firefox and Chrome). However, when I run the same Django application on a Centos server, both Firefox and Chrome prompt the user to save/download the svg file.

On that exact same Centos server, I have tried serving the exact same svg file using Apache as the webserver and voila, the file again is displayed directly on the browser (without any prompts)!

I can only attribute the difference in behavior to the built-in webserver on Django. It is somehow sending something to the browser which makes the browser think that the file needs to be downloaded rather than rendered directly.

Is there anything special that I need to do to make this work with Django on Centos (maybe some settings)? My centos release, Django, and Python versions are shown below:

Centos Release:

LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.7 (Final)
Release:        5.7
Codename:       Final

Django and Python:

(myenv)[root@foo bar]# python
Python 2.7.1 (r271:86832, Mar 17 2014, 11:59:55)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 6, 2, 'final', 0)

Thanks

Amit Saha
  • 11
  • 2

1 Answers1

0

Though avoiding Django's builtin web-server will solve this issue, I found the most relevant answer in another post: Can the Django dev server correctly serve SVG?. The correct answer to this problem is that in Centos the /etc/mime.types file does not have an entry for svg files. Here is the corresponding entry from Ubuntu:

> cat /etc/mime.types  | grep svg
image/svg+xml                                   svg svgz

So the solution to this problem is either of the following:

  1. Add the entry to /etc/mime.types files
  2. Add the following code to the "settings.py" file in Django:

    import mimetypes
    mimetypes.add_type("image/svg+xml", ".svg", True)
    mimetypes.add_type("image/svg+xml", ".svgz", True)
    

Thanks for all your comments.

Community
  • 1
  • 1
Amit Saha
  • 11
  • 2