Monday, April 3, 2017

Re: Will function based views ever be deprecated?

Try doing something that a class based view doesn't support out of the
box and then you'll understand why function based views are still used.
Even something as simple as returning some JSON means you have to dig
into how a class based view works where as it is about 3 lines of code
in a function based view.

Then what about a view that has to handle 2 (or more) different form
classes on the same page? You'll soon find that having to do that in a
class based view means major work rewriting or building your own class
based view.

As I said I'll give them another go but I've yet to be convinced of
their greatness.

On 03/04/2017 15:54, Andréas Kühne wrote:
> I find it interesting that so many haven't embraced the new CBV's. I
> ONLY use CBV's when designing and find the usages much simpler - because
> of no boilerplate and also the fact that I can derive from other classes
> when needed.
>
> Of course - the first time you use a form view or a template view and
> you find yourself having problems - debugging that could take a while,
> however, once you have done that I really haven't seen this as an issue.
> Also because most of the default views inherit from the same mixins -
> once you have understood how one works - you usually get the hang of it.
>
> It could be that the first thing I did in django was to refactor views
> from function based to class based - and therefore haven't started
> exploring FBV's more :-)
>
> Just my 2 cents...
>
> Regards,
>
> Andréas
>
> 2017-04-03 13:52 GMT+02:00 Some Developer <someukdeveloper@gmail.com
> <mailto:someukdeveloper@gmail.com>>:
>
> Hi,
>
> Awesome thanks. I can see the reason for some class based views as
> they remove the need for boilerplate code but if you run into a
> problem with them for whatever reason you generally have to dig out
> the Python debugger and set a break point in your view to see what
> the Django framework code is doing in the background.
>
> I can write just about any view I want in less than 5 minutes with a
> function based view. The only slow down on my end is my typing
> speed. I just find them much easier to understand and debug when you
> can look at the entire code for the view with nothing else getting
> in the way.
>
> I think I will try again to use some class based views in my code
> just so I can make a more informed decision. I just remember my last
> attempt to use the FormView class based view with multiple forms on
> the same page and giving up in disgust because it was so much harder
> than doing the same thing in a function based view.
>
> Some Developer.
>
> On 02/04/2017 06:37, James Bennett wrote:
>
> If you're asking "Will there ever be a point when all built-in
> views in
> Django are class-based", the answer is "maybe", because whether
> to write
> one of those class-based or function-based depends on what the view
> needs to do, how much configurability/extensibility it needs to
> support,
> etc.
>
> If you're asking "Will there ever be a point when Django no longer
> supports using functions as views, period", the answer is almost
> certainly "no".
>
> Officially, the definition of a Django view is a Python callable
> which
> takes an HttpRequest object as its first positional argument,
> and which
> either returns an HttpResponse object or raises an exception. That
> definition is unlikely to change.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d612ef6-4438-70ab-9aea-d5595af22e5a%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment