下面实现这些逻辑:
- CURD
- create
- Retrieve
- Update
- Delete
- List
第一天配置好Django环境和虚拟工作环境后完成简单的create逻辑,简单login逻辑,简单detail逻辑,简单update逻辑
from django.shortcuts import render,redirect from django.http import HttpResponse from .models import Todo from .forms import TodoForm def login(request): todo = Todo.objects.all() context = { "todo_list":todo } return render(request,"todo/login.html",context) def detail(request,id): todo = Todo.objects.get(id=id) context = { "todo":todo } return render(request,"todo/detail.html",context) # create account def create(request): form = TodoForm(request.POST or None) if form.is_valid(): # 创建新的代办并打印结果 form.save(); return redirect("/") # print(form.cleaned_data) # name = form.cleaned_data['name'] # due_date = form.cleaned_data['due_date'] # new_todo = Todo.objects.create(name=name,due_date=due_date) context = { "form":form } return render(request,"todo/create.html",context) def update(request,id): todo = Todo.objects.get(id=id) form = TodoForm(request.POST or None) if form.is_valid(): form.save(); return redirect("/") context = { "form":form } return render(request,"todo/update.html",context)
效果图:
额对于一个小白来说,第一天算是还可以了,明天完成剩余逻辑并对前端进行优化
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)