1
00:00:05,390 --> 00:00:09,130
Welcome everyone to the section of the course on a larger flask applications.

2
00:00:09,950 --> 00:00:15,740
So far we've been putting a lot of content into a single app that py file and as your applications begin

3
00:00:15,740 --> 00:00:21,080
to get larger a flask it typically makes more sense to separate portions of the application into their

4
00:00:21,080 --> 00:00:24,940
own files such as creating a model stop file a form that py file.

5
00:00:24,960 --> 00:00:26,310
And views that py file.

6
00:00:26,480 --> 00:00:30,830
And in fact we've already seen that a bit through a previous lectures separating some of these components

7
00:00:30,830 --> 00:00:36,410
that are getting too large for a single app that PI now for even larger applications.

8
00:00:36,440 --> 00:00:41,190
It actually begins to make sense three factor the files into separate components or directories.

9
00:00:41,330 --> 00:00:46,400
So then you'll actually have multiple forms views and templates for each major component of your web

10
00:00:46,400 --> 00:00:47,240
application.

11
00:00:48,460 --> 00:00:52,860
Let's re-imagine how we could restructure our puppy adoption site from the previous lectures.

12
00:00:53,050 --> 00:00:58,660
Well we're going to do is going to split our apple pie into separate components for each major aspect

13
00:00:58,810 --> 00:01:00,350
of our web application.

14
00:01:00,460 --> 00:01:06,030
One component for the puppies and one component for the owners so we're going to do is we'll have our

15
00:01:06,040 --> 00:01:09,590
apple pie file and the forms and views that go with it.

16
00:01:09,730 --> 00:01:12,100
And we're going to separate those into their own directories.

17
00:01:12,250 --> 00:01:17,200
We'll have at the Rectory for owners and we'll have forms and views and templates that are related to

18
00:01:17,200 --> 00:01:22,090
owners and then we'll have a directory for puppies were formed views and templates that are related

19
00:01:22,090 --> 00:01:25,040
to puppies will go.

20
00:01:25,100 --> 00:01:29,660
We're also going to be able to use the blueprints library to connect these separate modular components

21
00:01:29,750 --> 00:01:32,780
back to our main app Pietie I'll keep in mind.

22
00:01:32,900 --> 00:01:35,190
We're still keeping that app up high.

23
00:01:35,330 --> 00:01:38,310
However now it's going to just be referencing those subcomponents.

24
00:01:38,480 --> 00:01:43,940
This is really going to help you organize your code as you begin to create larger and larger flask applications.

25
00:01:45,020 --> 00:01:47,440
Let's view what the file structure will look like.

26
00:01:47,510 --> 00:01:52,520
This is best done by checking out the structure exampled a text file that's within the larger flask

27
00:01:52,580 --> 00:01:53,850
applications folder.

28
00:01:53,890 --> 00:01:58,370
I want to open up that text file and walk you through it then in the next lecture we'll restructure

29
00:01:58,370 --> 00:02:00,650
a project to fit this larger structure.

30
00:02:00,650 --> 00:02:01,130
All right.

31
00:02:01,130 --> 00:02:06,440
I've gone ahead and opened up the structure example text file and this basically lays out the structure

32
00:02:06,440 --> 00:02:07,550
we're going to be building.

33
00:02:07,700 --> 00:02:12,240
So you can see here the level designated by these actual indentations.

34
00:02:12,320 --> 00:02:16,790
So you can see what's inside my project and then what's inside my owner's we're going to walk through

35
00:02:17,180 --> 00:02:21,560
this overall directory to explain how we're actually going to structure a project now.

36
00:02:21,560 --> 00:02:26,780
So we still have at the very top level are at thought py file and this is the main application file

37
00:02:26,990 --> 00:02:30,570
to be called when you actually start the server for your web application.

38
00:02:30,800 --> 00:02:33,220
Then we're going to have a requirements that textfile.

39
00:02:33,350 --> 00:02:36,140
This is a file of Pippin's false statements for your app.

40
00:02:36,140 --> 00:02:40,400
So we're going to go over had actually create your own requirements text file then you're going to have

41
00:02:40,450 --> 00:02:47,150
a migration folder which is just created for migrations by automatically calling those flask DB calls.

42
00:02:47,300 --> 00:02:52,280
And then finally we'll have a large main project folder and this is where the subcomponents will be

43
00:02:52,280 --> 00:02:53,790
in separate folders.

44
00:02:53,810 --> 00:03:00,350
So at this top level you're going to have your models PI file in it that PI file as well as your actual

45
00:03:00,430 --> 00:03:01,690
sequelae database.

46
00:03:01,820 --> 00:03:08,210
And then also within my project have an owner's directory and a puppy's directory then within both owners

47
00:03:08,210 --> 00:03:13,090
and puppies you have forms and views that are related to things about the owners.

48
00:03:13,100 --> 00:03:17,720
So if you want to create a new owner that's going to be inside the forms that py file within the owner's

49
00:03:17,720 --> 00:03:18,460
directory.

50
00:03:18,620 --> 00:03:23,270
If you want to create a new puppy that's going to be within the forms that PI file of the puppies and

51
00:03:23,270 --> 00:03:25,370
then views associate of owners or puppies.

52
00:03:25,370 --> 00:03:28,330
That's going to be within those subdirectories as well.

53
00:03:28,340 --> 00:03:32,900
Now if you have a view or a form that doesn't really fall nicely into one of these categories like owner

54
00:03:32,900 --> 00:03:37,670
or puppies then you can always feel free to just put it back at the same top level or even just include

55
00:03:37,670 --> 00:03:43,110
it in the app that py file room or not everything's going to be able to nicely fit into a subcomponent.

56
00:03:43,250 --> 00:03:45,430
So that's really going to depend on case by case.

57
00:03:45,450 --> 00:03:48,900
And it's really up to you if you want to organize it in this fashion.

58
00:03:48,950 --> 00:03:54,080
Or if you want to just have one large app that PI file or forms and views at the top level again a lot

59
00:03:54,080 --> 00:03:56,920
of this starts to become kind of personal choice.

60
00:03:56,990 --> 00:04:01,100
Then again other owners and puppies they're each going to have their own templates folder and they will

61
00:04:01,100 --> 00:04:06,950
say owners again or puppies again and then the template files that belong to those particular components

62
00:04:06,950 --> 00:04:10,670
like an owner or add or delete list puppies.

63
00:04:10,880 --> 00:04:15,200
Then at the same level of puppies and owners you're going to have your static file that's where you

64
00:04:15,200 --> 00:04:21,770
would store your CSSA javascript images font files etc. and then you'll have template files and do templates

65
00:04:21,770 --> 00:04:23,230
that probably don't sync well.

66
00:04:23,240 --> 00:04:27,030
Any component such as the base H-2 him and the home page HTML file.

67
00:04:27,200 --> 00:04:31,400
The homey smell file that really doesn't belong to a particular component like puppies or owner's son

68
00:04:31,400 --> 00:04:31,640
said.

69
00:04:31,640 --> 00:04:37,610
We'll leave it at this top level template files and then within these puppies and owners we're going

70
00:04:37,610 --> 00:04:42,960
to introduce what's known as blueprints in order to successfully connect them to our top level apple

71
00:04:43,020 --> 00:04:43,990
pie.

72
00:04:44,050 --> 00:04:44,520
OK.

73
00:04:44,660 --> 00:04:51,040
So coming up next we're going to completely restructure our original adoption site to look like this.

74
00:04:51,050 --> 00:04:54,950
Keep in mind in the very next lecture it's super easy to accidently make a typo.

75
00:04:55,100 --> 00:05:00,070
So in case you get something or some error that's not letting you run the completed application.

76
00:05:00,170 --> 00:05:05,420
Make sure you copy and paste directly or just run our files directly from the larger flask applications

77
00:05:05,420 --> 00:05:06,280
folder.

78
00:05:06,290 --> 00:05:10,450
OK we'll see at the next lecture where we begin restructuring our project with blueprints.
