简体   繁体   中英

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

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"}),

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')),

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

A good solution is handling robots.txt via nginx :

location  /robots.txt {
    alias  /path/to/static/robots.txt;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM