我在django中重定向模板时传递了一个值



我创建了登录页面并提交了该页面它转到了另一个页面我想要在另一个页面上使用特定的用户名所以我在重定向页面时传递了该名称但它对我不起作用。

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

如果登录成功。您不需要在模板中传递用户名。您可以访问模板中的用户{{request.user}}{{request.user.username}}.

最新更新