WEBVTT 00:02.740 --> 00:06.110 It's finally time to start calling the end of the course project. 00:06.160 --> 00:11.730 As we said we're going to build a full fledged real world single page application and using django the 00:11.730 --> 00:13.430 rest framework and Abuja. 00:13.450 --> 00:14.260 Yes. 00:14.290 --> 00:18.940 As you can see I'm currently inside the repository folder for this project. 00:18.970 --> 00:25.180 It's always one of the most useful things that we can do when creating a new Django project is to initialize 00:25.270 --> 00:30.970 a beautiful environment so that then inside of this V12 environment we can then install all the dependencies 00:30.970 --> 00:32.260 that we're going to need. 00:32.260 --> 00:34.390 And that's precisely what I'm going to do now. 00:34.420 --> 00:42.400 So Python three dash M V and the anvil let's now activate pivot to environment. 00:42.420 --> 00:50.870 So source B and being activate and the two packages that we want to install first are of course Django 00:50.900 --> 00:55.530 and Django rest framework. 00:55.660 --> 01:02.590 We are in fact when we started several other packages later on but for now we can't first of all create 01:02.650 --> 01:09.250 the requirements that text file and we can now initialize our project. 01:09.250 --> 01:16.990 So Django I mean start project question time and there it is. 01:17.350 --> 01:20.450 So let's move inside of this folder. 01:20.500 --> 01:25.570 We've got a project we're going to create two applications questions which is going to manage all the 01:25.570 --> 01:31.900 code related to questions and answers such as for example models of views and so on and then we're going 01:31.890 --> 01:37.810 to ever use this application which is the name clearly suggests it's going to manage all the code related 01:37.810 --> 01:43.450 to the users on our platform and these users application is going to be the first one that we're going 01:43.450 --> 01:45.080 to create now. 01:45.160 --> 01:54.070 So Python managed that by start up users the new app is being created and we can now open up these words 01:54.070 --> 02:02.210 to your code inside of this folder as always the first thing that we bother to do is to select the Python 02:02.210 --> 02:08.780 interpreter for the project and we can see that the new virtual environment we've created in that Question 02:08.780 --> 02:16.370 Time folder is available and we've done we can now install our users application in this setting stood 02:16.370 --> 02:23.830 by file so you're users of course you also need to install Django framework. 02:23.840 --> 02:27.020 So rest framework. 02:27.230 --> 02:34.130 And considering that we're also going to use talking authentication we can also install rest framework 02:34.140 --> 02:36.730 adopt of token. 02:36.730 --> 02:41.510 And of course we also need a comma inside of the user's application. 02:41.510 --> 02:45.180 We want to go to the models not by fine first. 02:45.290 --> 02:50.660 And that's because for this project we want to use a custom user model even though we are not going 02:50.660 --> 02:57.080 to add any fields to the model itself when developing something new is always a good idea to think about 02:57.080 --> 03:02.310 the future of the project itself considering that we're developing a real world use case. 03:02.330 --> 03:08.120 That project is in fact very similar to most more than social networks having the ability to update 03:08.150 --> 03:12.590 the User model by design could be really really useful. 03:12.770 --> 03:18.260 In the previous sections of the course we've seen how we can extend the User model using a profile model 03:18.500 --> 03:23.300 but we've also talked about the fact that it was possible to extend the User model itself. 03:23.360 --> 03:30.410 And so in order to do so first of all we're going to need to import the abstract user model from Django 03:30.410 --> 03:38.480 dot country dot author dot models import abstract user. 03:38.480 --> 03:45.590 And if you take a look at its definition we see that it extends abstract base use and permissions Maxine 03:45.830 --> 03:52.040 providing us all the different fields that we're used to such as user name first name email ID stuff 03:52.220 --> 03:53.240 and so on. 03:53.270 --> 03:58.580 So the custom user model that we're going to create is in fact going to be very similar but one that 03:58.580 --> 04:00.980 is already used by Django. 04:00.990 --> 04:10.550 Let's go back to our models stood by file and here we can define class custom user extending abstract 04:11.090 --> 04:11.570 user. 04:11.930 --> 04:17.960 And here we can just use the bus instruction so that in the future in case you need to add new fields 04:17.960 --> 04:23.330 to the custom user mother you can just remove the pass distraction and define all the different fields 04:23.330 --> 04:24.300 that you might need. 04:24.410 --> 04:30.020 They use it model is a very important part of the authentication system in a Django project and that's 04:30.020 --> 04:34.330 why we now need to tell Django that we're using a custom model. 04:34.400 --> 04:38.680 So let's go to the settings that by file by the end of the file. 04:39.020 --> 04:49.400 Right here we now have to define off the user model equals users not cast on user. 04:49.400 --> 04:55.130 That's no go to that I'd dead by file so that we can register a custom use that as well. 04:55.130 --> 05:03.150 So you're going to board from Django dot country dot off dot Adgate. 05:03.320 --> 05:07.810 I'm going to import user admin and of course the model itself. 05:07.820 --> 05:13.440 So from users that models import custom user. 05:13.480 --> 05:23.060 Now we are we can define a class class custom user admin which is going to extend user I've been the 05:23.060 --> 05:25.510 one used as a default by Django. 05:25.770 --> 05:34.460 Yet we have to define model custom user and then we can define list display is going to be a list of 05:34.460 --> 05:35.470 course. 05:35.530 --> 05:45.250 And yet we can set user name then email and then maybe is stuff in case you want to add other fields 05:45.550 --> 05:47.250 to the custom user model. 05:47.290 --> 05:54.520 Remember that year you then need to specify ad form where you can define a custom form class to use 05:54.520 --> 06:03.120 to create new users and then a form class that you can instead use to update the different instances. 06:03.160 --> 06:10.750 We can however just register the new class right away so admin dot site that register and we're going 06:10.750 --> 06:20.140 to pass custom user and then of course custom user I mean like so is time to create and apply the migrations 06:20.200 --> 06:21.610 for our new model. 06:22.240 --> 06:34.730 So here Python managed that by make migrations and of course Python managed by migrate lets them create 06:34.790 --> 06:43.310 a new user and specifically of course a super user so Python Mannix does by create super user you can 06:43.310 --> 06:47.380 just call it Artemis let's nail Randy development server. 06:47.420 --> 06:54.230 So first of all we are going to set up at configuration and I want to have a Django configuration here. 06:54.290 --> 06:58.940 I'm going to comment out as always no threading. 06:59.000 --> 07:01.410 So let's run the development server. 07:01.580 --> 07:05.450 Let's move to Chrome and yet we can just go to slash. 07:06.110 --> 07:16.110 I mean I mean and as you can see we have Art users application and we can always check and update if 07:16.110 --> 07:16.930 we need you to. 07:17.100 --> 07:22.250 All the information about our user now that everything is working fine. 07:22.270 --> 07:27.160 We need to set that project so that users can create new accounts and authenticate them. 07:27.240 --> 07:32.010 And in order to do so as we've seen in the previous sections we need to install a couple of packages. 07:32.080 --> 07:39.720 Beep first of all people install Django rest of their winning free style Django or Laufer. 07:39.800 --> 07:50.200 So people who start Django are lawful and then you can start Django registration which provides us all 07:50.200 --> 07:53.170 the views needed to create new accounts in your browser. 07:53.320 --> 08:02.360 And then we can install Django Krispie forms to create good looking forums easily that's now move to 08:02.360 --> 08:08.040 the settings not by file because of course we need to register all the new applications we've just installed. 08:08.090 --> 08:24.010 So first of all I love then we're going to have a Olof that so show and all of the social account then 08:24.090 --> 08:32.850 yes we need to install rest of them and rest of the registration. 08:32.950 --> 08:39.250 And as you might remember we also need to add another application this time one of Django is applications 08:39.370 --> 08:41.130 which is Django country. 08:41.140 --> 08:48.110 That sites and let's not forget crispy forms of course crispy forms. 08:48.550 --> 08:53.320 And if you've never heard about this package it's a really useful package we use to create good looking 08:53.320 --> 08:56.470 forums and as we'll see using it is very easy. 08:56.470 --> 09:04.290 First of all we need to define down here Crispy template Tucker. 09:04.420 --> 09:10.350 Yeah we define how we want our forums to look like in this case we want him to look like bootstrap for 09:10.480 --> 09:11.300 for himself. 09:11.740 --> 09:15.880 And of course later on we'll see how to actually use them in the HDMI templates. 09:15.880 --> 09:22.230 We don't need to set aside ideas to one for the site's application and to register new accounts via 09:22.300 --> 09:22.790 arrested. 09:22.810 --> 09:25.640 We want to disable the email verification settings. 09:25.810 --> 09:34.240 Yeah we can do account email vilification and can set none. 09:34.370 --> 09:45.470 But we want a user to actually include an email anyway so account email required equals through and 09:45.530 --> 09:46.940 let's also add some comments. 09:47.000 --> 09:52.490 So this is about the custom user model. 09:52.490 --> 09:57.560 This is about Django Krispie forms. 09:57.680 --> 10:08.540 This is about Django country that sites and this is about Django Olof. 10:09.800 --> 10:17.410 Now that all the settings are in place and in fact this is not a loft not social but all of that account. 10:17.480 --> 10:21.450 Now that everything is in place let's apply all the migrations for the new applications. 10:21.470 --> 10:30.020 So Python managed that by migrate and lets them move to the Urals not by file in order to define all 10:30.020 --> 10:33.960 the different rural parts and end points for a project. 10:33.980 --> 10:46.800 First of all right here I'm going to define path API author like so and yeah we can include rest framework 10:47.050 --> 11:01.400 that you also then come up like so and yeah we can define API slash rest author to include rest of dot 11:01.540 --> 11:09.880 your Elsa and then let us paste it once again like so including registration end point we arrest. 11:09.910 --> 11:16.090 So this is going to be API rest of the registration. 11:16.540 --> 11:22.840 And yeah we can include the rest of the dot registration don't to adults. 11:22.900 --> 11:25.490 So this is about logging in your browser while API. 11:25.550 --> 11:28.660 Logging of your arrest and registration of your arrest. 11:29.010 --> 11:33.110 We now need to add it looking and the registration parts to use your browser. 11:33.210 --> 11:36.330 That's out the logging one first so path. 11:37.420 --> 11:47.140 And yet we can simply define accounts and we can include the normal URLs used by Django Django of the 11:47.140 --> 11:48.070 country. 11:48.070 --> 11:53.590 Not often thought your answer regarding the registration parts instead. 11:53.690 --> 11:55.610 Things are going to be a little bit different. 11:55.630 --> 12:00.640 We're going to use the views provided by the Django registration package even though those views expect 12:00.640 --> 12:03.140 us to use a default user model. 12:03.190 --> 12:06.140 And considering that of course we're using a custom user. 12:06.280 --> 12:10.420 We also need to create a custom forum to use with django registration. 12:10.540 --> 12:23.210 So yeah we can create a four by file like so and yeah first of all from django registration forms. 12:23.590 --> 12:32.300 Import registration form and yeah of course from users not models. 12:32.360 --> 12:42.050 Import custom user and then you do we can define classic custom user form which is going to extend the 12:42.050 --> 12:50.980 registration form and yet inside we can define classic meta which can extend registration form that 12:51.530 --> 12:57.510 matched up so that year we only have to define model equals custom user. 12:57.590 --> 13:00.890 We can now import the form in that you arrested by file. 13:01.400 --> 13:10.910 So from users that forms import custom user form so that we can now use it with the registration view 13:11.120 --> 13:13.700 provided by django registration. 13:13.700 --> 13:23.780 So yeah are only to import it of course from django registration dot McCann's DOT wants to epic that 13:24.600 --> 13:32.330 museum import registration view and not this year I am using their one step views so that we can skip 13:32.390 --> 13:39.860 email verification for now but I can include the are illegal to that django registration and documentation 13:40.040 --> 13:44.200 so that you can learn how to set up an email verification system in case you need to. 13:44.270 --> 13:51.260 Let's not create the path itself so I'm going to copy this one like so and this is going to be accounts 13:51.860 --> 14:02.520 register and yet I'm just going to use registration of you dot s view and you don't need to pass a series 14:02.520 --> 14:03.790 of parameters. 14:04.200 --> 14:13.210 First of all form Classic which is going to be of course custom user form and then we need to pass this 14:13.220 --> 14:21.150 access you had l we can just set it as deep on page and any idea we also need to set a name for the 14:21.150 --> 14:21.660 path. 14:21.690 --> 14:28.730 So name and we have to set it as Django registration and this core register. 14:29.340 --> 14:34.330 But let's also include all the other you add else provided by the package. 14:34.390 --> 14:41.700 So specifically I'm just going to copy these strings like so that's why I'm going to include Django 14:41.710 --> 14:44.800 distillation that McCance not one step to address. 14:44.970 --> 14:47.630 So let's make a brief recap of what we have here. 14:47.640 --> 14:49.910 First of all of course the admin area. 14:49.950 --> 14:56.100 So then we have a path to this custom version of the registration view provided by django registration 14:56.160 --> 14:59.340 that we use to create new accounts via your browser. 14:59.340 --> 15:02.680 Then we have other you add s used by the django registration package. 15:02.710 --> 15:06.780 The log in your Ls provided by Django to log in users via a browser. 15:06.780 --> 15:14.100 Then we have log in the URL for the browser API the log in and points to use the arrest and the registration 15:14.100 --> 15:18.030 and point to use the arrest whilst being dead. 15:18.030 --> 15:27.210 We need to do is to go to the settings notify file and now we need to set logging trail equals counts 15:28.410 --> 15:44.290 logging then logging redirect you have l equals just the page and then logout at a direct link and we 15:44.290 --> 15:49.260 can set the page as well so that after log out considering that the on page will only be available to 15:49.270 --> 15:53.930 authenticated users looking for will be shown right away. 15:53.980 --> 15:55.480 So this is it for this lesson. 15:55.630 --> 16:00.130 We'll see how to set the rest of the authentication components such as for example the templates in 16:00.130 --> 16:00.640 the next one.