Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to render a html page without view model?

Tags:

django

Is there a way to render a html page without having a view model in django if a page is going to display only static html?

Also, can I redirect to a html page instead of a url? For example, instead of doing this:

return HttpResponseRedirect('form/success/')

can I do this:

return HttpResponseRedirect('success.html')

?

like image 912
iJK Avatar asked May 09 '10 22:05

iJK


2 Answers

direct_to_template no longer works in Django 1.8. Here is how to do it in 1.8, in the urls.py:

from django.views.generic import TemplateView

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name="your_static.html"), name='whatever'),
]
like image 74
Cheng Avatar answered Oct 04 '22 19:10

Cheng


You can render a template without a view using the generic view direct_to_template.

Redirecting to success.html isn't the way to go in django since success.html doesn't have an associated URL. You always have to bind the template to an url via a view (direct_to_template is a view which gets all its arguments from the conf in urls.py, but it's still a view)

like image 41
Guillaume Esquevin Avatar answered Oct 04 '22 20:10

Guillaume Esquevin