Django User registration

This week I was focusing on creating the user registration page for the website. This section took a while. As an unexpected bug occurred in the process. To start making the register page we have to copy some of the code from the base.html file. By copying the code blocks we get the repeatable code from the other pages like sidebar, navigation bar and style. Now we just have to fill it out with content. This is where the code for the form itself will be. first, we want to have a div tag to make the code more readable and assign it settings in the future. <div class="content-section"> will be name of the tag.

The next line we can add the form tag with the POST method. A POST method is simply data that is sent to the server. This is one of many methods used in the HTTPS protocol. Now, this we can to add something which is Django specific. We need to have a code block including a certain token {% csrf_token %} which stands for Cross Site Request Forgery protection which protects the page attacks where a malicious site has a link, form button or javascript. which is used for a certain action on your website. Uses the credentials of the login in person. After adding that code block to the form we define the fieldsets. We define the fieldset class as from-group <fieldset class="form-group"> And we can big text on top of the form like join today <legend class="border-bottom mb-4">Join Today</legend> If the user does not have account. Then we add the code block form {{ form }} One of the good things about Django is that reduce the need for boilerplate code helps the developer focus on uniques solutions to the project on hand. After this we can make another div tag with the name form-group <div class="form-group">. Under this tag, we can contain the button.

This will be the sign-up button so the user submits the details of the form to the server. For the button, we can add some bootstrap code to it. button class="btn btn-outline-info" is a button bootstrap class. This simply crates button in an outline. type="submit" simply submits the info as this is a form. After that we can add text under form for extra infomation. Here we just have a sign in link if the user allready has an acount.

<div class="border-top pt-3">

<small class="text-muted">

Already Have An ancount? <a class="ml-2" href="#">Sign in</a>

</small>

The small tag will simply just make the text one size smaller than the HTML document. We also add a dew bootstrap classes to these tags. The link for the sign in page has a pound sign (#) which makes it a dead link. As we do not yet have a sign in page. Now we have the view for the resginster page we can set the logic for the form. We can set up a new file called forms.py where we can create the fields for the forms. Django has lots of a avabible code to use for this so we can simply import them to the file.

Tobi Olabode