contact@digitalnotebooks.co
Stay Organized, Stay Inspired. Let's Write.

Registration Module: Part 14

Back To All Notes
  • Notebook: Django: Automating Common Tasks
  • Speaker: Udemy Instructor Rathan Kumar
  • Date Created: Aug. 16, 2024, 11:45 p.m.
  • Owner: Rosilie

1. We need a URL pattern like  http://127.0.0.1:8000/register/, so in the main project's URLS.PY.

2. Create the REGISTER function in VIEWS.PY:

3. Create the REGISTER.HTML in TEMPLATES.

4. We update our REGISTER.HTML to include our Django tags.

{%extends 'base.html' %}

{% block content %}

<we add our unique code here>

{% endblock %}

5. We update our BASE.HTML to link our webpages to REGISTER.HTML

6. To create the registration form, we can manually create the UI form or automate this using DJANGO MODEL FORM (similar to our Admin Panel User Registration) WITH CRISPY TO FORMAT IT.

7. Create a new file, FORMS.PY,  in your main project directory.

8. In our VIEWS.PY, we write:

9. In our REGISTER.HTML, we write

10. If we use the conventional way to set up the form, it shall be like this:

{%extends 'base.html' %}

{% block content %}

<form action="">

    {{ form.as_p }}

</form>

{% endblock %}

11.  To format this form, we can use the CRISPY FORM. See this for the CRISPY FORM DOCUMENTATION.

Install Django Crispy Form: $ pip install django-crispy-forms

In your SETTINGS.PY, register this in your INSTALLED_APPS

12. If you check your BASE.HTML the bootstrap we are using is version 5, that is why our CRISPY_TEMPALTE_PACK='bootstrap5' and so we need to install this as well.

$ pip install  crispy-bootstrap5

Register this in your INSTALLED_APPS:

 

13. Update our REGISTER.HTML and reload:

14. Further updating our REGISTER.HTML.

15. In the default User Form, the email is an optional field. We can make this as a required field by updating our FORMS.PY

16. Our VIEWS.PY as:

17. Testing the registration form with an existing user:

17. To include our message alert for successful registration.

18. I updated the form to include the firstname and the lastname in the registration.

19.

 



No PDF file attached.

Notebook
Notebook Details
Title: Django: Automating Common Tasks
Category: Coding