Brett Brett - 5 months ago 16x
Python Question

Django - redirect to a static html file

I have a

app (I'm fairly new so I'm doing my best to learn the ins and outs), where I would like to have a url endpoint simply redirect to a static html file in another folder (app).

My project file hierarchy looks like:

- html/
- index.html

looks like:

from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView

urlpatterns = patterns('',
url(r'^docs/$', RedirectView.as_view(url='/docs/html/index.html')),

However, when I navigate to
I see the browser redirect to
, but the page is not accessible.

Is there any reason that the
would not be avalable to the
application in a redirect like this?

An pointers would be greatly appreciated.


NOTE: direct_to_template has been deprecated since Django 1.5. Use TemplateView.as_view instead.

I think what you want is a Template View, not a RedirectView. You could do it with something like:

from django.conf.urls import patterns, include, url
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
    (r'^docs/$', direct_to_template, {
        'template': 'index.html'

Just ensure the path to index.html is in the TEMPLATE_DIRS setting, or just place it in the templates folder of your app (This answer might help).