[英]Django - what is the difference between render(), render_to_response() and direct_to_template()?
[英]What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9
我想將主頁設為index.html
,它位於名為templates/castle_tm/index.html
的模板目錄中,但是URL顯示
“沒有名為簡單的模塊”。
在django> 1.4中不贊成使用基於通用的視圖。 現在,我如何將主頁重定向到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"}),
在最新版本的django中,您可以使用TemplateView
from django.views.generic import TemplateView
...
url(r'^api/casinova$', TemplateView.as_view(template_name='castle_tm/index.html')),
我相信您正在尋找TemplateView
from django.views.generic import TemplateView
url(r'^api/casinova$', TemplateView.as_view(template_name="castle_tm/index.html")),
基於泛型的視圖已被基於類的泛型視圖所取代,這使您可以輕松地覆蓋它們,以提供額外的上下文數據並減少代碼重復
有關更多信息,Russell Keith-Magee幾年前在djangocon上做了非常出色的演講,您可以在這里觀看- 基於類的視圖:過去,現在和將來
一個好的解決方案是通過nginx
處理robots.txt
:
location /robots.txt {
alias /path/to/static/robots.txt;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.