1
00:00:05,300 --> 00:00:05,950
Welcome back.

2
00:00:05,990 --> 00:00:10,310
We're going to finish off this section of the course with a little coda long project with forms and

3
00:00:10,310 --> 00:00:11,750
flash.

4
00:00:11,950 --> 00:00:16,090
We want you to expand the code from the previous lecture to do the following.

5
00:00:16,090 --> 00:00:22,210
I want to add a string field for Breede save that input for the breed to the session and then send the

6
00:00:22,210 --> 00:00:25,540
Flast message to the user indicating their choice of breed.

7
00:00:25,540 --> 00:00:32,140
Upon hitting submit so because there's really only a few extra lines of code needed to do this I want

8
00:00:32,140 --> 00:00:35,960
you to first try to add them on your own and see if you can get it to work.

9
00:00:36,010 --> 00:00:40,690
This lectures also going to serve as a code along lecture for example solution because they're really

10
00:00:40,690 --> 00:00:42,210
just a few lines you need to add.

11
00:00:42,280 --> 00:00:45,220
We're not going to bother splitting this into an exercise or solution.

12
00:00:45,340 --> 00:00:49,120
We're just going to now continue on to show you what the solution should look like.

13
00:00:49,120 --> 00:00:53,830
Let me briefly introduce what the final web page is going to look like.

14
00:00:53,870 --> 00:00:55,630
I'm actually just going to bring it over here.

15
00:00:55,870 --> 00:00:57,670
So what are you going to do.

16
00:00:57,680 --> 00:01:02,560
It's going to ask you what Bredar you are going to be able to enter whatever breed you want hit submit

17
00:01:02,650 --> 00:01:06,580
and then you should see something that says you just change your breed to and then whatever the user

18
00:01:06,580 --> 00:01:07,390
submitted.

19
00:01:07,390 --> 00:01:12,850
So if I change this to be something like pootle and hit submit the update to poodle and I should be

20
00:01:12,850 --> 00:01:15,490
able to dismiss that flash message again.

21
00:01:15,520 --> 00:01:20,470
Not that many actual lines of code from the previous lecture to actually add in that functionality.

22
00:01:20,470 --> 00:01:22,590
So go ahead try to attempt this on your own.

23
00:01:22,720 --> 00:01:27,160
It's up to you if you want to start from scratch or just out on the few extra lines to the previous

24
00:01:27,160 --> 00:01:28,230
lecture.

25
00:01:28,240 --> 00:01:31,510
OK let's code along an example solution to get this effect.

26
00:01:32,710 --> 00:01:33,020
All right.

27
00:01:33,020 --> 00:01:38,300
Here I am at the text editor I have the code from last time where we just have a simple submit button

28
00:01:38,600 --> 00:01:39,410
and then we flashed.

29
00:01:39,410 --> 00:01:44,870
You just click the button and redirect to the home page with that flash and then on our index Tim L..

30
00:01:45,020 --> 00:01:47,830
Basically the same thing for messaging get flash messages.

31
00:01:47,960 --> 00:01:51,780
We replay that message here and then we have the form.

32
00:01:51,800 --> 00:01:59,140
So the first thing we need to do is in our simple form I'm going to add a breed and call this string

33
00:01:59,140 --> 00:02:04,970
field and then we'll ask what breed are you question mark.

34
00:02:05,110 --> 00:02:08,050
Let's make sure we actually import it string field and it looks like we did.

35
00:02:08,050 --> 00:02:11,620
So there will be two forms we just need to add in Springfield.

36
00:02:11,620 --> 00:02:18,610
Now that I have that field what I'm going to do is come down here to form that validate on submit.

37
00:02:18,610 --> 00:02:21,280
Notice that if we scroll back up I've also imported session.

38
00:02:21,460 --> 00:02:27,130
So I'm going to use that to grab the Breit and then I'm going to set that as part of my flash message.

39
00:02:27,160 --> 00:02:28,030
So how can I do that.

40
00:02:28,090 --> 00:02:37,510
Well instead of saying Just flash you click the button I'm going to say if for for the session set the

41
00:02:37,510 --> 00:02:50,090
Breede key equal to form outbreed data and then I will say flash in here I'm going to say you just changed

42
00:02:51,120 --> 00:03:00,660
your breed to and then I'm going to answer session breed and in order to use this sort of insertion

43
00:03:00,780 --> 00:03:06,270
I'm going to use string interpolation So this only works if Python 3.6 or higher.

44
00:03:06,270 --> 00:03:07,210
Keep that in mind.

45
00:03:07,230 --> 00:03:12,210
The alternative to do that is to say that format and then format it that way.

46
00:03:12,210 --> 00:03:13,940
So right now we're just going to have that.

47
00:03:13,980 --> 00:03:15,510
So I have an F string literal.

48
00:03:15,510 --> 00:03:19,400
I'm grabbing formed outbreed saving it to my session and then flashing.

49
00:03:19,410 --> 00:03:23,700
You just change your Breede session outbreed or excuse me session Breede here.

50
00:03:23,700 --> 00:03:26,260
That's actually all I need to do in my H HTML file.

51
00:03:26,280 --> 00:03:29,770
So I'm going to save this come back to my index study each time.

52
00:03:30,060 --> 00:03:34,820
I actually don't need to change anything for the get flashed messages because it's just going to pass

53
00:03:34,830 --> 00:03:40,760
in get flash messages and this mess is then going to be this flash right here you just change your breed

54
00:03:40,760 --> 00:03:43,320
to whatever that breed in the session is chosen.

55
00:03:43,380 --> 00:03:53,690
What I have to do is just add in form dog that label and then form that Breit.

56
00:03:53,700 --> 00:03:56,090
OK so now that we have that ready to go.

57
00:03:56,210 --> 00:04:00,760
Let me make sure we save that and then I'm going to say Python.

58
00:04:00,780 --> 00:04:05,780
They basic that PI enter and let's check to see that everything ran well and that we don't have any

59
00:04:05,780 --> 00:04:06,390
bugs.

60
00:04:06,560 --> 00:04:11,620
So bringing in my browser if we're running that says what breed are you going to choose pootle I'll

61
00:04:11,620 --> 00:04:12,780
just click me.

62
00:04:12,980 --> 00:04:18,260
I get this flash message change of read to pootle I can dismiss it because that bootstrap code if I

63
00:04:18,260 --> 00:04:19,850
choose lab hit click me.

64
00:04:19,840 --> 00:04:21,510
It says you just change your Bre to laugh.

65
00:04:21,760 --> 00:04:22,200
OK.

66
00:04:22,340 --> 00:04:24,230
That's really all you had to do for this project.

67
00:04:24,230 --> 00:04:29,820
Again the main changes we did is we added a new field to our form.

68
00:04:29,870 --> 00:04:36,350
We saved that form data to the session and then in our flash message we report back that session Breede

69
00:04:36,610 --> 00:04:41,090
remember just using string interpolation here as discussed in the structure in the Python section of

70
00:04:41,090 --> 00:04:41,780
the course.

71
00:04:41,810 --> 00:04:45,400
Lots of different ways you can formatted this and then back in the h t m l.

72
00:04:45,410 --> 00:04:48,960
The only thing we really change here is just adding that breede to the form.

73
00:04:49,370 --> 00:04:55,220
OK that ends our discussion of forms and fields and all that good stuff with flask and hopefully now

74
00:04:55,220 --> 00:05:00,200
you get to see how easy it is to create forms and connect them from your temple of H-2 mill to your

75
00:05:00,200 --> 00:05:01,760
actual flask application.

76
00:05:01,970 --> 00:05:06,330
Well we haven't really discussed yet is actually saving that user input data to a database.

77
00:05:06,470 --> 00:05:09,880
So the entire next section is just going to be a discussion on databases.

78
00:05:10,010 --> 00:05:11,280
So let's get started.

79
00:05:11,300 --> 00:05:12,890
I'll see you at the next section of the course.
