2016-04-01 22 views
7

मैं index.html जो templates/castle_tm/index.html के रूप में नामित टेम्पलेट निर्देशिका के अंदर स्थित है के रूप में अपने घर पृष्ठ बनाना चाहते में django.views.generic.simple आयात direct_to_template से के बराबर है, लेकिन यूआरएलक्या Django 1.9

से पता चलता

"कोई मॉड्यूल सरल नाम नहीं है"।

जेनेरिक आधारित विचार 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"}), 
+0

आप इस सवाल का जवाब यहाँ मिल सकती है - http://stackoverflow.com/questions/11428427/no-module-named-simple-error-in-django –

+0

धन्यवाद @ मुकुंद गंडलुर – shalin

उत्तर

6

मेरा मानना ​​है कि आप देख रहे हैं एक TemplateView

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

जेनेरिक आधारित विचारों ने ले ली है कक्षा आधारित जेनेरिक विचार जो आपको अतिरिक्त संदर्भ डेटा प्रदान करने और कोड दोहराव

अधिक जानकारी के लिए, रसेल कीथ- मैगी djangocon पर एक बहुत अच्छी प्रस्तुति कुछ साल पहले किया था, तो आप इसे यहाँ देख सकते हैं - Class-based Views: Past, Present and Future

+1

इसका काम किया .. धन्यवाद @Sayse – shalin

11

Django के नवीनतम संस्करण में आप उपयोग कर सकते हैं TemplateView

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

इसके काम धन्यवाद @ v1k45 – shalin

संबंधित मुद्दे