'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 1:[1]
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}}.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manoj Kamble |
