2011-10-30 2 views
3

나는 djangos 새로운 클래스 기반의 일반적인 전망이를 에뮬레이션하기 위해 노력하고있어 그것을 알아낼 수 없습니다 :django에서 클래스 기반 일반 뷰를 사용하여 동적 템플릿 이름을 어떻게 지정합니까?

urlpatterns = pattern('', 
(r'^about/(\w+)/$', about_pages), 
) 

def about_pages(request, page): 
    return direct_to_template(request, template="about/%s.html" % page) 

이 클래스를 기반으로 전망 그냥 수 있습니까? as_view()를 덮어 써야합니까? 그렇다면 어떻게해야할까요?

답변

5

시도해보기 (테스트하지 않음) :

 
class AboutView(TemplateView): 
    def get_template_names(self): 
     return ["about/%s.html" % self.args[0]] 

관련 문제