• django的闪现和增、删、改、查


    使用 messages 闪现
    在views.py中导入
    from django.contrib import messages

    在html中
    {% if messages %}
    {% for mess in messages %}
    <font size="5" color="red">{{mess}}</font> <br><br>
    {% endfor %}
    {% endif %}


    django中的增删改查


    def dele(request):
    id = request.GET.get('id')
    dele = models.Department.objects.filter(id=id).delete()
    return redirect('index')



    def amend(request):
    id = request.GET.get('id')
    course = models.Department.objects.get(id=id)
    if request.method == 'POST':
    department_name = request.POST.get('department_name')
    department_work = request.POST.get('department_work')
    course.save()
    return redirect('index')
    return render(request,'web/department_add.html',locals())


    在首页显示name
    def index(request):
    if request.method == 'GET':
    account = request.session.get('account')
    user= models.Teacher.objects.filter(account=account).first()
    if not account :
    return redirect(reverse('login')) #在首页展示登录人的名字

    return render(request,'web/index.html',locals())

    在首页显示账号
    def index(request):
    if request.method == 'POST':
    name = request.POST.get('name')
    date = models.Staff.objects.filter(name=name).all()
    return render(request,'web/index.html',locals())

    退出该用户
    def delete(request): # 退出
    dele = request.session.get('account')
    if dele:
    del request.session['account']
    return redirect(reverse('index'))


    def index(request): #首页
    if request.method == 'POST':
    datas = models.Department.objects.all()
    date = models.Staff.objects.all()
    return render(request,'web/index.html',locals()) #搜索

  • 相关阅读:
    洛谷 P1919 【模板】A*B Problem升级版(FFT快速傅里叶)
    Codeforces Goodbye 2018
    ubuntu 百度云
    【UOJ 351】新年的叶子
    【SDOI2008】仪仗队
    NOI 2002 贪吃的九头龙
    最大获利
    codeforces 814E An unavoidable detour for home
    codeforces 814D An overnight dance in discotheque
    bzoj3191 [JLOI2013]卡牌游戏
  • 原文地址:https://www.cnblogs.com/gaxy/p/10764656.html
Copyright © 2020-2023  润新知