2

I am trying to get class name of Generic view like below

class TestView(TemplateView):
   print self.__class__.__name__

But self is referring to app name rather TestView. My expected result is TestView.

Edit:

In the above code self does not work. Please refer comments. My requirement is to access TestView name.

2
  • 2
    That's not your code, because that wouldn't work at all (self is not defined at that point). Please show your actual code and output. Commented Jul 7, 2014 at 20:18
  • @DanielRoseman Sorry for the noise, I was referring other line's log above the class as output. I figured out now. Commented Jul 7, 2014 at 20:26

1 Answer 1

2

the code you provided does not work at all ... so I am making some assumptions here

class TestView(TemplateView):
   def __init__(self,*args,**kwargs):
       TemplateView.__init__(self,*args,**kwargs)
       print "I am",self.__class__.__name__
       print "My File:",self.template_name


class Whatever(TestView):
   pass


print Whatever()
print TestView()
Sign up to request clarification or add additional context in comments.

2 Comments

But I am using the code like class TestView(TemplateView): template_name = 'admin/index.html' and views.TestView_asview(). Could you please let me know how can I accommodate this requirement with your code. Actually I am trying to refer html file based on the TestView. For example TestView.html
maybe my edits will fix your issue ... i dont understand what your comment has to do at all with self.__class__.__name__

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.