[HN Gopher] Django Views - The Right Way
       ___________________________________________________________________
        
       Django Views - The Right Way
        
       Author : sgt
       Score  : 47 points
       Date   : 2023-06-10 19:08 UTC (3 hours ago)
        
 (HTM) web link (spookylukey.github.io)
 (TXT) w3m dump (spookylukey.github.io)
        
       | adamckay wrote:
       | I'd agree that CBV's can be difficult to reason with (though I
       | personally still use them for _most_ views) but the following two
       | websites have massively helped me make sense of them. The only
       | thing missing really is the actual flow of a request, such as
       | knowing `dispatch() - > get() -> get_context_data()` but it's not
       | terribly difficult to work out and learn.
       | 
       | https://ccbv.co.uk/
       | 
       | https://www.cdrf.co/
        
         | Nextgrid wrote:
         | For anyone struggling with remembering class based view mixins,
         | I suggest you get yourself a proper IDE that allows you to
         | trivially look into the implementation of anything as well as
         | lookup any symbol with fuzzy search. PyCharm/IntelliJ is one.
         | 
         | Since using such an IDE I pretty much never have to rely on the
         | documentation because it's much easier to Cmd+click into a
         | symbol and look at its implementation.
        
       | BiteCode_dev wrote:
       | Ok I was ready to hate this article the second I read the title,
       | and I clicked on it just to get enough ammunition to crap on it.
       | 
       | But it's actually quite good and I came to similar conclusions
       | after trying to make CBV work for years.
       | 
       | Plus it's well written.
       | 
       | Damn.
        
       | sergioisidoro wrote:
       | The most important caveat that the author mentions: this advice
       | may not apply to Django Rest Framework.
       | 
       | Class based views for DRF are awesome because they represent a
       | resource. It has been a great experience writing REST APIs with
       | class based views, and it reduces boilerplate with a tolerable
       | amount of implicit logic.
       | 
       | But as soon as I need to render a simple html page from a
       | request, I share the frustration of the author.
        
       | kolanos wrote:
       | Function based views are good until you have to handle many
       | request methods, then they become a hideous series of
       | if/elif/else.
        
         | notagoodidea wrote:
         | Or a good opportunity for match/case if >3.9.
        
       ___________________________________________________________________
       (page generated 2023-06-10 23:00 UTC)