Up until this point we have only created users from the command line and were logging into our accounts using the django admin dashboard. This is obviously not ideal and does not work if we want people to be able to create accounts from the front end of our site. This tutorial will show you how to create a sign up page where users can create an account.
Installing Crispy Forms
The first thing we should do before continuing is install a pip package called crispy forms which does some nice styling of our forms for us.
To do this simply run: pip install django-crispy-forms from the command line.
Now that we have installed crispy we need to add the following line into settings.py to configure what css framework it will use.
This can go anywhere in the file.
Creating a New Application
We will start by creating a new application that will hold all of the pages and functionality of our user sign up and log in. I will call my application "register".
To create a new app run: python manage.py startapp
After we have done this we will need to add the app to our project from settings.py within our mysite directory.
Creating a Sign Up Page
Fortunately for us Django has created a few templates that we can modify to create a sign up page. The first step to start using these is to create a new file inside of our register app called forms.py.
The file should contain the following:
By doing this we have modified the default sign up page and added an email field. If there are other feilds that you would like to add define them as calss variables and add them into the "field" list in the order you'd like them to appear in the form.
Creating the View
Now time to write the html that will render our sign up page!
We will start by creating a new templates folder inside of our register app. Then we will create a folder inside templates called "register". Finally we will create "register.html" in that folder.
Now we need to add a function inside the views.py file of our register app to render this page.
Finally we need to add a url to this page. We will do this from the urls.py file inside of the mysite directory.
If you've done all of the steps outlined above you should now have a functional sign up page that you can access by going to /register.