首页 > 解决方案 > 没有 django.forms 的 Django CRUD 系统通过 {{ id }} 来查看函数

问题描述

我正在编写一个 CRUD(不使用 django.forms 或通用表单)我无法将 id 值从 toUpArti() 传递给 updateArti() 谁能告诉我如何或提及解决此问题的另一种方法


文章/views.py:

def toUpArti(request, arti_id):

    d = ArticleItem.objects.get(id=arti_id)

    return render(request, 'artiUp.html')



def updateArti(request):

    u = ArticleItem.objects.filter(id=x).update(title=request.POST['title'],
                                               body=request.POST['body'])
    return HttpResponseRedirect('/article/')

标签: pythondjangodjango-templatescrud

解决方案


我假设您的网址类似于

path('article/<int:arti_id/', views.toUpArit, name='view-article')

那么你的回报应该是HTTPRespoonseRedirect(reverse('view-article', kwargs='arti_id:u.id}))

使用DRY 原则


推荐阅读