How to redirect page to another page in django for class based view? -
i new in django therefore don't know how redirect page page in django. please me solve issue. urls.py
file
urlpatterns = patterns('', url(r'^demo$', views.booklist.as_view(), name='demo'), )
this views.py
file
class booklist(listview): model = book template_name = "demo.html"
here trying redirect demo.html
file. didn't error code still page not redirected.
to make view
redirect page, have specify url
should redirect.
you don't "redirect"
template, "render"
template. can redirect url renders template.
to redirect in view, can use redirectview
. redirect given url.
example:
suppose there view myview
has url
defined in it. then, whenever there request
myview
, redirect specified url
.
class myview(redirectview): url = 'my_redirect_url'
you can pass url
directly in urls.py
like:
url(r'^my_view_url/$', redirectview.as_view(url='my-redirect-url'))
in above code, there no error because listview
takes template_name
attribute. use template
display list of book
objects. here there no redirection happening, infact, template demo.html
being rendered displays list of book
objects.
class booklist(listview): model = book template_name = "demo.html"
Comments
Post a Comment