1
00:00:00,499 --> 00:00:02,257
- [Narrator] Hi, and
welcome back to the course.

2
00:00:02,257 --> 00:00:03,902
In this video, we're going to get started

3
00:00:03,902 --> 00:00:06,431
coding our new project.

4
00:00:06,431 --> 00:00:08,891
Now, our project is starting to grow,

5
00:00:08,891 --> 00:00:12,123
and it will do so more and
more throughout this section,

6
00:00:12,123 --> 00:00:13,480
so it's going to make sense for us

7
00:00:13,480 --> 00:00:16,359
to start using folders to make sure

8
00:00:16,359 --> 00:00:18,970
our code is a bit more organised.

9
00:00:18,970 --> 00:00:22,887
Now, folders in Python
are also called packages

10
00:00:24,776 --> 00:00:26,422
most of the time.

11
00:00:26,422 --> 00:00:29,150
So, what we're going to do is
create a couple of packages.

12
00:00:29,150 --> 00:00:30,160
And there's a minor difference

13
00:00:30,160 --> 00:00:31,542
between a package and a folder

14
00:00:31,542 --> 00:00:33,571
and we're going to see that in a moment.

15
00:00:33,571 --> 00:00:35,237
The first thing we have to do is to,

16
00:00:35,237 --> 00:00:38,222
in our code folder,
right-click here on Atom

17
00:00:38,222 --> 00:00:40,060
and create a new folder

18
00:00:40,060 --> 00:00:43,620
and we're going to call this "models".

19
00:00:43,620 --> 00:00:46,357
And then, outside the models folder...

20
00:00:46,357 --> 00:00:48,927
So just beside it, we're going
to create another folder,

21
00:00:48,927 --> 00:00:52,072
which we're going to call "resources".

22
00:00:52,072 --> 00:00:54,214
Okay, and I put that
inside the models folder,

23
00:00:54,214 --> 00:00:57,536
so all we have to do is
drag it out and that's fine.

24
00:00:57,536 --> 00:01:00,243
Okay, so now the models
and the resources folder

25
00:01:00,243 --> 00:01:04,056
are side by side, not
one inside of another.

26
00:01:04,056 --> 00:01:04,889
Okay?

27
00:01:06,408 --> 00:01:09,589
Now, these two things here are folders.

28
00:01:09,589 --> 00:01:12,061
They're not packages.

29
00:01:12,061 --> 00:01:14,335
And in Python 3.5, this difference

30
00:01:14,335 --> 00:01:16,792
starts to make less sense,

31
00:01:16,792 --> 00:01:19,561
but certainly in Python
2.7 and earlier versions,

32
00:01:19,561 --> 00:01:21,375
this makes a lot of a difference.

33
00:01:21,375 --> 00:01:24,521
What we have to do to
make these things packages

34
00:01:24,521 --> 00:01:26,429
are to create a new file

35
00:01:26,429 --> 00:01:28,596
and call it "__init__.py".

36
00:01:32,021 --> 00:01:32,854
Okay?

37
00:01:33,890 --> 00:01:38,088
And similarly, in the
models, a new file there

38
00:01:38,088 --> 00:01:39,838
called "__init__.py".

39
00:01:42,734 --> 00:01:47,134
Make sure that that is two
underscores on each end.

40
00:01:47,134 --> 00:01:49,107
And all that does is it tells Python

41
00:01:49,107 --> 00:01:53,274
that it can look inside these
folders for Python files.

42
00:01:54,784 --> 00:01:57,000
If you don't have the init.py

43
00:01:57,000 --> 00:01:58,815
and you're using Python 3.5,

44
00:01:58,815 --> 00:02:00,871
it will most likely work.

45
00:02:00,871 --> 00:02:02,910
But if you're doing an
older version of Python,

46
00:02:02,910 --> 00:02:05,301
then it won't really look in those folders

47
00:02:05,301 --> 00:02:07,634
unless you have the init.py.

48
00:02:09,204 --> 00:02:10,707
Okay?

49
00:02:10,707 --> 00:02:13,455
Now the next thing we're going to do is

50
00:02:13,455 --> 00:02:16,455
we're going to look into the item.py

51
00:02:17,657 --> 00:02:20,657
and realise that we have a resource.

52
00:02:22,813 --> 00:02:24,651
And then at the very bottom
we've got an item list

53
00:02:24,651 --> 00:02:28,818
which is a resource and the
user.py is also a resource

54
00:02:29,870 --> 00:02:32,098
or should be a resource there as well.

55
00:02:32,098 --> 00:02:34,410
The UserRegister thing here.

56
00:02:34,410 --> 00:02:36,502
So, what we're going to do is

57
00:02:36,502 --> 00:02:40,502
we are going to move the
user and the item files

58
00:02:43,127 --> 00:02:45,246
into the resources folder.

59
00:02:45,246 --> 00:02:47,865
We're going to deal with
the class User in a moment.

60
00:02:47,865 --> 00:02:50,756
That's not a resource, so it
doesn't belong in this folder.

61
00:02:50,756 --> 00:02:54,420
But the UserRegister class does
belong in the folder, okay?

62
00:02:54,420 --> 00:02:55,610
So what we've done is...

63
00:02:55,610 --> 00:02:57,089
I'm going to close all these tabs.

64
00:02:57,089 --> 00:03:00,247
...is we've moved the
item and the user files

65
00:03:00,247 --> 00:03:02,094
into the resources folder

66
00:03:02,094 --> 00:03:05,949
because they mostly contain resources.

67
00:03:05,949 --> 00:03:09,513
We're going to move the
class User out of here soon,

68
00:03:09,513 --> 00:03:10,918
but not just now.

69
00:03:10,918 --> 00:03:12,458
In the next video.

70
00:03:12,458 --> 00:03:14,172
Okay, so now we've moved these things

71
00:03:14,172 --> 00:03:16,849
into the resources package, rather.

72
00:03:16,849 --> 00:03:19,715
I've been calling it folder,
but really it's package.

73
00:03:19,715 --> 00:03:22,314
Now we have to make sure
that the other files

74
00:03:22,314 --> 00:03:26,156
know where these files have moved to.

75
00:03:26,156 --> 00:03:28,406
So let's go into the app.py

76
00:03:29,715 --> 00:03:33,382
and notice that here
we're importing from user

77
00:03:33,382 --> 00:03:37,690
and that just looks at
the user file beside app,

78
00:03:37,690 --> 00:03:39,399
but that no longer exists.

79
00:03:39,399 --> 00:03:41,482
Now it is resources.user.

80
00:03:42,957 --> 00:03:45,549
And that's going to look
in the resources package

81
00:03:45,549 --> 00:03:47,815
and find the user file.

82
00:03:47,815 --> 00:03:48,696
Okay?

83
00:03:48,696 --> 00:03:51,249
And the same thing for resources.item.

84
00:03:51,249 --> 00:03:53,689
It's going to look in
the resources package

85
00:03:53,689 --> 00:03:56,148
and then in the items file.

86
00:03:56,148 --> 00:03:59,065
And that's all the changes
we have to do in the app.py.

87
00:03:59,065 --> 00:04:01,665
But remember we've also got security.py

88
00:04:01,665 --> 00:04:04,869
which imports user, so we
have to make sure to add

89
00:04:04,869 --> 00:04:07,286
resources.user there as well.

90
00:04:08,462 --> 00:04:10,761
An interesting thing
though, the User class

91
00:04:10,761 --> 00:04:14,494
that we've been talking
about is not a resource.

92
00:04:14,494 --> 00:04:16,927
The UserRegister class is a resource.

93
00:04:16,927 --> 00:04:20,897
So, once again, the User
class is not a resource.

94
00:04:20,897 --> 00:04:23,151
The UserRegister class is a resource,

95
00:04:23,151 --> 00:04:26,051
so we know the User class doesn't belong

96
00:04:26,051 --> 00:04:29,542
inside the resources package, and...

97
00:04:29,542 --> 00:04:31,995
But it is there for now,
so we have to make sure

98
00:04:31,995 --> 00:04:35,998
to import it correctly
from our security file.

99
00:04:35,998 --> 00:04:37,627
Okay?

100
00:04:37,627 --> 00:04:39,135
That's everything for this video.

101
00:04:39,135 --> 00:04:40,578
Do make sure to go to Postman

102
00:04:40,578 --> 00:04:41,849
and verify this all works

103
00:04:41,849 --> 00:04:43,580
just as it did in the last section.

104
00:04:43,580 --> 00:04:44,624
We're not going to do that here

105
00:04:44,624 --> 00:04:48,034
because we've not actually changed any...

106
00:04:48,034 --> 00:04:49,590
things that our code does.

107
00:04:49,590 --> 00:04:52,408
We've only really move things about.

108
00:04:52,408 --> 00:04:53,964
So, believe me, it does work

109
00:04:53,964 --> 00:04:54,837
and in the next video,

110
00:04:54,837 --> 00:04:57,504
we're going to continue
improving this code.

111
00:04:57,504 --> 00:04:59,190
So I'll see you there.

