Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Iam Passing an value when iam redirecting the template in django

I created Login Page and I submitted that page it goes to another page I want that particular username on another page so I am passing that name when I am redirecting the page but it doesn’t work for me…

urls.py
from django.contrib import admin
from django.urls import path
from .import views

urlpatterns = [
         path('dash/',views.Dash,name='Dash'),
]


Dash.html
<div class="flex-grow-1">
<span class="fw-semibold d-block">{{name}}</span>
</div>


views.py
def Login(request):
    if request.method=='POST':
     username=request.POST['username']
     password=request.POST['password']
     user=auth.authenticate(username=username,password=password)
     if user is not None:
         request.session['user'] = username
         auth.login(request,user)
         return redirect('/dash',{name:user})

This is my code why I am not getting the name? Please anyone help me

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If login is successful. You don’t need to pass the username in the template. You can access the user in template as {{request.user}} and username as {{request.user.username}}.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading