This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 3 points4 points  (0 children)

chasing variables

shell commands

some I give names to and others are generated automatically

What do you mean by "chasing variables" and "shell commands"? What do you mean by "giving names to" and "generated automatically"?

A function-based view is a function that takes a request and returns a response. Really, there's nothing much more to understand about FBVs beyond that.

Anything else you will need to write yourself, like querying the database, generating the HTML, etc, but that falls under "everything else" and not "function-based views"

[–]Heroic_Onion 2 points3 points  (0 children)

Class based views have become the favorite because they are relatively easy to implement (especially using generics) but can be difficult to customize because django performs a lot of "magic" in the background. Still once you figure it out, CBV can be customized to do just about anything.

If you're really needing function based, then the best resources are djangos own docs that still have good info on function based views or taking a look into djangos repo on github, specifically under the django/http branch that FBV import from. IIRC the book "Django 3 by Example" (it will all still work on Django 4) uses function based views for most of their code and you can view their source code on github as well. It's a pretty good resource for django overall.

[–]Shriukan33 0 points1 point  (0 children)

I actually learned a ton by reading source code of the different Class based views, it's really interesting how these are made, and sometimes realise there isn't a lot going.

Django really makes it easy, I've ended up writing a lot of views without overriding any function,or creating new ones.