login community faq

I'm building a django site, but I have a lot of static files from my old server served at the root directory that I want to still work.

For example these links should still work, even though there is now a django site at the top level as well.

www.domain.com/one.jpg
www.domain.com/two
www.domain.com/two/index.html

I have all the old static files stored under /home/username/webapps/static/.

I want it so that the static file is served if it exists, if not send the url to django to process.

How can I achieve this?

asked Jan 21 '11 at 18:25

Jakob's gravatar image

Jakob
315

edited Jan 21 '11 at 18:25


Hi Jakob,

In this case what you should do is create the URLs in your Django app's urls.py file then doing something like a direct_to_template:

http://docs.djangoproject.com/en/dev/ref/generic-views/

to still serve the files/pages you had there.

answered Jan 21 '11 at 18:42

klynton's gravatar image

klynton ♦♦
148128

Hi, I can see how that would work for a few pages, but would this work for other files, like zip files? I sent hundreds of URLs to clients in the past year including lots of zip file URLs and I'd like all these URLs to keep working. Ideally I don't want to list them all out, since there are hundreds, but I can since they shouldn't be changing any more now that new stuff will be handled in django.

(Jan 21 '11 at 18:50) Jakob Jakob's gravatar image

I found this info about using mod_wsgi to handle static files, would this be applicable? http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files

I suppose I will try that...

(Jan 21 '11 at 19:09) Jakob Jakob's gravatar image

That should definitely work! It's probably a better solution for all of those files as well.

(Jan 21 '11 at 19:17) klynton ♦♦ klynton's gravatar image

Ok, got it working with mod_rewrite. I added the following to my httpd.conf, before the django WSGIScriptAlias. This checks if the request matches a filename or directory in the static directory, else sends the request on to django.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
RewriteEngine on

#   first try to find it in static/...
#   ...and if found stop and be happy:
RewriteCond         /home/user/webapps/static/%{REQUEST_FILENAME}  -f [OR]
RewriteCond         /home/user/webapps/static/%{REQUEST_FILENAME}  -d
RewriteRule  ^(.+)  /home/user/webapps/static/$1  [L]

#   else go on for other Alias or ScriptAlias directives,
#   etc.
RewriteRule   ^(.+)  -  [PT]

answered Jan 22 '11 at 09:05

Jakob's gravatar image

Jakob
315

edited Jan 22 '11 at 09:21

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×643
×90

Asked: Jan 21 '11 at 18:25

Seen: 1,109 times

Last updated: Jan 22 '11 at 09:21

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited