django,前端for ,if ,和直接取变量,

    xiaoxiao2022-07-12  152

    添加页

    #后台返回数据 data = Users.objects.all() content = {userllist:data} return render(request,lala/lala/la.html,content) # 前台接收时应该用 {% for i in userlist %} <td class="am-text-middle">{{ v.nikename }}</td> <td class="am-text-middle">{{ v.phone }}</td> <td class="am-text-middle">{{ v.email }}</td> <td class="am-text-middle">{{ v.age }}</td> <td class="am-text-middle"> {% if v.sex == '0' %}{% elif v.sex == '1' %}{% else %} 保密 {% endif%} </td> <td class="am-text-middle"> <select class="select-status" style="color:red;"> <option value="0" {% if v.status == 0 %} selected {% endif %}>正常</option> <option value="1" {% if v.status == 1 %} selected {% endif %}>禁用</option> </select> </td> {% endfor %} <div class="am-form-group"> <label for="user-name" class="am-u-sm-3 am-form-label"> 性别 </label> <div class="am-u-sm-9"> <label class="am-radio-inline"><input type="radio" value="0" {% if uinfo.sex == '0' %} checked {% endif %} name="sex"></label> <label class="am-radio-inline"><input type="radio" value="1" {% if uinfo.sex == '1' %} checked {% endif %} name="sex"></label> </div> </div>

    直接取变量

    uid = request.GET.get('uid') ob = Users.objects.get(id=uid) context = {'uinfo':ob} return render(request,'myadmin/users/edit.html',context) #前端接收应该用 {{uinfo.name}}
    最新回复(0)