Django

College Event Registration Website

CampusConnect Introduction and Setup Configuring settings file for template, static and media files Setting up Tailwind Creating Custom User Model Creating Super User for CampusConnect Registering Custom User Model Search and Filter for User Model Serving Media Files During Development Categorizing Departments Linking Department with HOD Creating Abstract Model for Event Creating Model for Workshop Customizing Admin Page for Workshop Update in Model AbstractEvent Adding Instructor for Workshop Instructor Model Admin Page Adding Poster Field in Abstract Event Providing Access to HOD Access Update for HOD Restricting HOD Access to Particular Department AbstractEvent On Spot Registration Field Creating Workshop Object Creating and Linking Home Page Displaying Workshop on Home Page Styling Home Page Adding Workshop Detail Page Link Workshop Detail Page Workshop Detail Page Styling Workshop Instructor Details Workshop Detail Contact Contact Admin Page Many to Many Field for Contact Displaying Contact on Workshop Detail Page Adding Title for Workshop Detail Page Adding Gallery for Workshop Workshop Gallery Admin Page Displaying Gallery Images on Website Through Context Displaying Gallery Images on Website through template tags Authentication for users User Registration User Registration Submission Logout Functionality For User Login Functionality for User Model For Workshop Registration Workshop Registration Admin Page Register Workshop Function Register Button in Workshop Page Validations Before Workshop Registration Workshop Registration Closed Validaiton User Already Registered for Workshop Validation Workshop Registration Report From Admin Page Export using Library in Django Admin Extending Abstract Event for Hackathons

Logout User

As you used the login() function from the django auth module, to login a specific user, similarly you can use the logout() fucntion from the django auth module to logout a user from the website.

Create a function for logout in your authentication/views.py file. This function logouts the user and redirects him to a particular page (register page).

from django.contrib.auth import logout
def user_logout(request):
    logout(request)
    return redirect('register')

A route needs to be created for this function which can be done as follows by editing the urlpatterns inside the authentication/urls.py file:

path("logout", views.user_logout, name='logout'),

After this, whenever the http://127.0.0.1:8000/logout url is visited it will logout the user from the website.

Lets add the logout button inside the home.html file.

<a href="{% url 'logout' %}">Logout</a>

Inside the single quotes the specfic name which is given inside the urlpatterns should be there.

After these changes, the webpage would look like this : alt text On clicking the logout button the user would be redirected to the register page and he would need to login to visit this page again.

Previous Register User
Next Login User