简体   繁体   English

在django 1.9中相当于django.views.generic.simple import direct_to_template

[英]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 我想将主页设为index.html ,它位于名为templates/castle_tm/index.html的模板目录中,但是URL显示

"no module named simple". “没有名为简单的模块”。

Generic based views are deprecated in django >1.4. 在django> 1.4中不赞成使用基于通用的视图。 Now, How can i redirect the home page to index.html 现在,我如何将主页重定向到index.html

urls.py 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 在最新版本的django中,您可以使用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 我相信您正在寻找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 有关更多信息,Russell Keith-Magee几年前在djangocon上做了非常出色的演讲,您可以在这里观看- 基于类的视图:过去,现在和将来

A good solution is handling robots.txt via nginx : 一个好的解决方案是通过nginx处理robots.txt

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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