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 >
<span >{{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
CodePudding user response:
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}}.