Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
What are Forms in Django?1:58 with Kenneth Love
Very few web apps get by without taking some sort of user input. Most of the time, that input comes in through a form. Let's look at how forms are created in Django and all ways and reasons we can use them.
[MUSIC] 0:00 Hi there. 0:04 I'm Kenneth, the Django teacher here at Treehouse. 0:05 In Django Basics, we covered a good chunk of what Django gives you for 0:08 making web apps in Python. 0:12 In short, it gives you well, a lot. 0:13 But we didn't get to cover a really powerful part 0:16 of the Django framework, forms. 0:19 Now if you're familiar with HTML, 0:22 and I'll assume that you are, you might immediately think, forms, so what? 0:23 I can make forms all day long. 0:27 And you totally can. 0:29 Forms in Django though do a little bit more than just make HTML. 0:30 In Django, forms serve three purposes. 0:34 They help us quickly generate HTML to represent a form, with specific widgets, 0:37 or inputs, and all sorts of other goodies. 0:41 They let us validate any sort of external data. 0:44 If you can put it into a dictionary, you can quickly validate it with a Form. 0:47 This is a great shortcut for making sure that, for 0:51 example, an API gave you valid data for your purposes. 0:53 With another Django feature, Model Forms, we can quickly create form versions of our 0:57 models, and then, with validated data, quickly create or update model instances. 1:01 If you've done the Build a Social Network with Flask course, we used a forms library 1:07 for Flask that let us create HTML forms and validate their data. 1:11 We'll be doing something very similar to that in this course. 1:15 We're going to make a basic form to let people suggest new content that we 1:19 should cover. 1:22 We'll have to make a view or two to handle that too. 1:23 And we'll do some custom validation on it. 1:25 After that, 1:29 we're going to look a little bit more at models, especially their inheritance. 1:29 We'll need these so that we can add quizzes, questions, and 1:33 their answers to our education app. 1:36 And finally, we'll make a few model forms for our new models. 1:38 In fact, we're going to make a mini CMS, a quiz builder for our site. 1:41 Our site, by the way, 1:45 is going to look different in this course than it has so far. 1:46 I finally sat down and created a nice look for 1:50 it since we're going to be spending a lot more time looking at it. 1:51 So if you're ready, I'm ready. 1:55 Let's get started with Django forms. 1:57
You need to sign up for Treehouse in order to download course files.Sign up