jball037
jball037

Reputation: 1800

Serve media files with Django on production server

I know you're not technically supposed to do this, but I have no choice, I need to launch my site today. And since this is my first Django app, I just realized that setting DEBUG=False causes media files to no longer be served by Django in production.

What is the quickest and dirtiest way to get Django to serve my media files? Any help is infinitely appreciated!

Upvotes: 3

Views: 2167

Answers (3)

jball037
jball037

Reputation: 1800

Here's what I ended up doing. I just added the below to my apache2.conf file and it worked great:

Alias /media/ /home/Mysite/mediaroot/

<Directory /home/Mysite/media>
Order deny,allow
Allow from all
</Directory>

Apache serves my media now :)

Upvotes: 6

Daniel Roseman
Daniel Roseman

Reputation: 599450

There is no quick and dirty way. There is only the way to actually do it: point Apache to the media folder and set STATIC_URL to the URL that Apache is using.

Upvotes: 5

Chris Hawkes
Chris Hawkes

Reputation: 12410

I think I'm confused,

Normally in a production environment I set my static url and media_url to the designated folders on my server.

Then my templates reference,

<img src="{{ MEDIA_URL }}images/image1.jpg" />

My settings file would look like this,

MEDIA_URL = "http://www.noobmovies.com/static/"

and it serves CSS, JavaScript etc...

I'm not sure there is anything dirty or inappropriate about it.

Upvotes: 1

Related Questions