Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9

Tags:

python

django

I want to make my home page as index.html which is located inside the template directory named as templates/castle_tm/index.html, but the url shows

"no module named simple".

Generic based views are deprecated in django >1.4. Now, How can i redirect the home page to index.html

urls.py

from django.conf.urls import url, patterns, include
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
from castle import views
from django.views.generic.simple import direct_to_template
admin.autodiscover()
url(r'^api/casinova$', direct_to_template,{"template":"castle_tm/index.html"}),
like image 454
shalin Avatar asked Apr 01 '16 06:04

shalin


People also ask

What is a generic view in Django?

Imagine you need a static page or a listing page. Django offers an easy way to set those simple views that is called generic views. Unlike classic views, generic views are classes not functions.

What is the best way to present a view in Django?

The direct_to_template view certainly is useful, but Django’s generic views really shine when it comes to presenting views on your database content. Because it’s such a common task, Django comes with a handful of built-in generic views that make generating list and detail views of objects incredibly easy.

What is a base view in Django?

A base view for displaying a single object. It is not intended to be used directly, but rather as a parent class of the django.views.generic.detail.DetailView or other views representing details of a single object. This view inherits methods and attributes from the following views:

What is an object list view in Django?

Because it’s such a common task, Django comes with a handful of built-in generic views that make generating list and detail views of objects incredibly easy. Let’s take a look at one of these generic views: the “object list” view.


2 Answers

In latest versions of django you can use TemplateView

from django.views.generic import TemplateView
...
url(r'^api/casinova$', TemplateView.as_view(template_name='castle_tm/index.html')),
like image 55
v1k45 Avatar answered Sep 26 '22 03:09

v1k45


I believe you're looking for a TemplateView

from django.views.generic import TemplateView
url(r'^api/casinova$', TemplateView.as_view(template_name="castle_tm/index.html")),

Generic based views have been replaced by class based generic views which allows you to override them easily to provide extra context data and reduce code repetition

For more information, Russell Keith-Magee did a very good presentation at djangocon a couple of years ago, you can watch it here - Class-based Views: Past, Present and Future

like image 31
Sayse Avatar answered Sep 26 '22 03:09

Sayse