in Education by
Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page that displays a user. This page is very similar to page that displays a group, but it's still not so similar to just use another data model. Group also has members etc... One way would be to point views to class methods and then extend that class. Has anyone tried this approach or has any other idea? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I've created and used my own generic view classes, defining __call__ so an instance of the class is callable. I really like it; while Django's generic views allow some customization through keyword arguments, OO generic views (if their behavior is split into a number of separate methods) can have much more fine-grained customization via subclassing, which lets me repeat myself a lot less. (I get tired of rewriting the same create/update view logic anytime I need to tweak something Django's generic views don't quite allow). I've posted some code at djangosnippets.org. The only real downside I see is the proliferation of internal method calls, which may impact performance somewhat. I don't think this is much of a concern; it's rare that Python code execution would be your performance bottleneck in a web app. UPDATE: Django's own generic views are now class-based. UPDATE: FWIW, I've changed my opinion on class-based views since this answer was written. After having used them extensively on a couple of projects, I feel they tend to lead to code that is satisfyingly DRY to write, but very hard to read and maintain later, because functionality is spread across so many different places, and subclasses are so dependent on every implementation detail of the superclasses and mixins. I now feel that TemplateResponse and view decorators is a better answer for decomposing view code.

Related questions

0 votes
0 votes
    Views are created on top of Materialized views a. False b. True...
asked Feb 19, 2023 in Technology by JackTerrance
0 votes
    Views stores the data and you can refresh it on timely bases a. False b. True...
asked Feb 19, 2023 in Technology by JackTerrance
0 votes
    Give your views on the policy ‘Atoms for Peace’. Please answer the above question....
asked Aug 18, 2022 in Education by JackTerrance
0 votes
    Illustrate the differences in world views between India and Pakistan. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    I want to combine two views in one dashboard in google analytics report. I want the tracked buttons up ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I want to combine two views in one dashboard in google analytics report. I want the tracked buttons up ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I have a drawer menu, which allows users to enter filter details, which will update a recycler view list ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am starting with CakePHP. After a document has been uploaded to my server then the user tries to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm using ActionMailer in my application and I want to use localized views for email templates. It seems ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is the purpose of creating views in SQL? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Elaborate the five types of Views available in a presentation. Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    What are the various views which you can open your presentation in? Explain Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    Materialised views make sure that (a) View definition is kept stable (b) View definition is kept up-to ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...