2013-06-29 2 views
1

내 장고 프로젝트에서는 도움말 페이지, 우리 페이지, 자주하는 질문 페이지 등에 대한 정적 페이지를 만들어야했고 사용자 이름이 어딘가에 나타났습니다. 이 페이지에서는 일반 뷰로 호출되기 때문에 템플릿에 변수를 보내는 방법을 모르지만 일반 뷰에 관한 것입니다.일반 뷰에 의해 호출 된 템플릿에 변수를 보내는 방법

미리 감사드립니다.

+0

나는 당신의 질문은 이미 여기에 대답이라고 생각 : [http://stackoverflow.com/questions/7470539/passing-request-user-to-template-in-django][1] [1] : http://stackoverflow.com/questions/7470539/passing-request-user-to-template-in-django – AgileDeveloper

답변

2

@ Jingo가 말한 게시물을 참조하십시오. 일부 변수를 일반 뷰에 추가하려면 'get_context_data '기능을 덮어 씁니다.

class ExampleView(TemplateView): # Or another generic view 
    template_name = "example.html" 

    def get_context_data(self, **kwargs): 
     context = super(ExampleView, self).get_context_data(**kwargs) 
     #If you dont call 'super', you wont have the context processor varibles 
     # like 'user' 
     context['var_name'] = "var content" # you can add template variables! 
     return context # dont forget to return it!