Tuesday, March 10, 2009

Django static pages

Serving static pages with django is mentioned here:
http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs

However, I could not find help to serve index.html (or crossdomain.xml :) ).

Here is how I did it :
in your URLconf file (urls.py). Add the following:

(r'^(?P.*)$', MainPage),


And the following function in your views.py (Which you will need to import into your urls.py of course !)

in the header:

from django.views.static import serve

and define the following :


def MainPage(request,path):
if path == "":
return HttpResponseRedirect('/web/index.html')
return serve(request,'/'+path,'./web')

Congratulations ... you should now be serving pages from ./web of your current django directory. Also you can serve index.html and crossdomain.xml :).

The above should do the trick .... enjoy!

No comments:

Post a Comment