1

I am new to django and in my current job i had to edit the existing code. Now i am not able to find in the documentation where i can find all methods which can be over ridden and what they are suppose to do. In mY views file someone has defined these functions but i don't know what they are supposed to do.

Like

def get_context_data(self, **kwargs):
def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
def get_success_url(self):
def form_valid(self, form):

Now i am not sure if he as write his new methods or He is overriding the buil in methods because he is not calling them anywhere.

can someone guide where are these methods defined in documentation so that i can see what are some other methods and what they do

2 Answers 2

1

I found this resource really uesful, as it saves you having to manually trace inheritance hierarchies to check which methods a class has.

http://ccbv.co.uk/

The official documentation is here, depending on your django version:

https://docs.djangoproject.com/en/1.3/ref/class-based-views/

https://docs.djangoproject.com/en/1.4/ref/class-based-views/

https://docs.djangoproject.com/en/dev/ref/class-based-views/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that was great info. Although its bit confusing in start but i will get there
0
  • get_context_data returns the data that will be accessible in your template
  • get is all the actions that are performed when a page is loaded
  • post is all the actions that are performed when data is posted to a url
  • get_success_url returns the url that the user will be directed to after a post was succesfully made
  • form_valid here you can add extra actions to the form validation

2 Comments

so u mean , these methods are factory methods and don't need to be explicitly called in view
Yes they are defined in some of the classes that can be extended, you do not have to extend them, only if you want some added custom behaviour.

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.