标签:html
登录成功显示绿色,失败显示红色
在上一节基础上:
样式中加入:
.greenspan{color:green}
.redspan{color:red}
最后加一个result变量,后面加上safe
Result后面加safe
{{result|safe}}
对于单个变量,可以在其后面加上safe过滤器,告诉Django这个字符串不用进行HTML转义
加上一个简单的登陆函数
def userLogin(uname,upass):
if uname == "shenyi" and upass == "123":
return True
else:
return False
def hi(request):
beijin = {"id":1,"dd":"北京"}
shanghai = {"id":2,"dd":"上海"}
userAreas = [beijin,shanghai]
dataset = {‘result‘:‘必须输入数字‘,"areas":userAreas}
if userLogin(request.POST.get("txtUserName"),request.POST.get("txtUserPass")):
dataset[‘result‘] = ‘<span class="greenspan">登录成功</span>‘
else:
dataset[‘result‘] = ‘<span class="redspan">登陆失败</span>‘
return render_to_response("index.html",dataset)
request.POST.get("txtUserName")
request.POST.get("txtUserPass")
分别得到输入框中用户名和密码的值
本文出自 “dba天空” 博客,请务必保留此出处http://9425473.blog.51cto.com/9415473/1702121
标签:html
原文地址:http://9425473.blog.51cto.com/9415473/1702121