gpt4 book ai didi

python - 如何在html页面上添加注释

转载 作者:行者123 更新时间:2023-12-01 05:04:57 24 4
gpt4 key购买 nike

我使用命令提示符运行我的 python 服务器,其中显示下面的打印语句(如果到达)。如何在模板 login.html

上显示它们

View .py
def home(request):
templatename="login.html"
if request.method=="POST":
u=request.POST.get("username")
p=request.POST.get("password")
user=authenticate(username=u, password=p)
if user is not None:
if user.is_active:
print "This User is valid, active and authenticated"
login(request,user)
return HttpResponseRedirect("/welcome/")
else:
print("This User is valid but the account has been disabled")
else:
print("The Username and Password entered were incorrect")
else:
user=None
return render_to_response(templatename,{'user': user},RequestContext(request))

最佳答案

将要在模板 login.html 上显示的语句存储在变量(此处为“状态”)中,如下所示:

def home(request):
templatename="login.html"
if request.method=="POST":
u=request.POST.get("username")
p=request.POST.get("password")
user=authenticate(username=u, password=p)
if user is not None:
if user.is_active:
state="This User is valid, active and authenticated"
login(request,user)
return HttpResponseRedirect("/welcome/")
else:
state="This User is valid but the account has been disabled"
else:
state="The Username and Password entered were incorrect"
else:
user=None
return render_to_response(templatename,{'user': user,'state':state},RequestContext(request))

将字典中的状态传递给render_to_response()。
访问 login.html 页面中的状态为 {{state}}。
你的工作已经完成。

关于python - 如何在html页面上添加注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25226045/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com