WebFaction
Community site: login 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 21 Jan '11, 18:25

Jakob
3236
accept rate: 0%

edited 21 Jan '11, 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.

permanent link

answered 21 Jan '11, 18:42

klynton
1.6k1210
accept rate: 41%

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.

(21 Jan '11, 18:50) Jakob

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...

(21 Jan '11, 19:09) Jakob

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

(21 Jan '11, 19:17) klynton

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.

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]
permanent link

answered 22 Jan '11, 09:05

Jakob
3236
accept rate: 0%

edited 22 Jan '11, 09:21

Your answer
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×910
×125

question asked: 21 Jan '11, 18:25

question was seen: 3,515 times

last updated: 22 Jan '11, 09:21

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM