I'm trying to get '/'
to redirect to '/first-page'
where '/first-page'
is a built-in flat page with the slug first-page
I'm looking for something like
(r'^/', 'redirect_to', {'url': '/flat-page'}),
I'm trying to get '/'
to redirect to '/first-page'
where '/first-page'
is a built-in flat page with the slug first-page
I'm looking for something like
(r'^/', 'redirect_to', {'url': '/flat-page'}),
Use Django's generic views
urlpatterns = patterns('django.views.generic.simple',
('^$', 'redirect_to', {'url': '/first-page'}),
)
urlpatterns += patterns('myProject.myApp',
...
)
or
urlpatterns = patterns('',
('^$', 'django.views.generic.simple.redirect_to', {'url': '/first-page'}),
...
)
See the docs for more info and examples.
Watch your URL matching too, that one you have will match anything starting with /. Like example.com//anything, note the double slash.
Inside the view for the url, you can use HttpResponseRedirect
.
from django.http import HttpResponseRedirect
def rootview(request):
return HttpResponseRedirect('/flat-page')
Use HttpResponsePermanentRedirect
:
from django.http import HttpResponsePermanentRedirect
# ...
(r'^$', 'redirect_to', lambda request: HttpResponsePermanentRedirect('/flat-page')),