def deleteitem(request, projectname, itemname):
try:
project = Project.objects.get(user=request.user, project_name=projectname)
except Project.DoesNotExist:
return HttpResponseNotFound('Nothing is here.')
try:
item = Item.objects.get(project=project, item_name=itemname)
except Item.DoesNotExist:
return HttpResponseNotFound('Nothing is here.')
if request.method == 'GET':
# using the form that was used for deleting the project
form = DeleteProject()
return render(request, 'deleteitem.html',
{'username': request.user.username, 'form': form, 'projectname': projectname, 'itemname': itemname})
elif request.method == 'POST':
if 'cancel' in request.POST:
return HttpResponseRedirect(reverse("listitems", args=(projectname,)))
elif 'submit' in request.POST:
item.delete()
return HttpResponseRedirect(reverse("listitems", args=(projectname,)))
views.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录