首页 > 解决方案 > 如何将计算变量保存在 django 数据库中并在之后加载?

问题描述

我正在制作一个简单的计算应用程序,但我想将计算的变量保存在数据库中,以便在需要时加载它们。谢谢

def showvideo(request):
    allvideos = Video.objects.all()
    form = VideoForm(request.POST or None)
    if form.is_valid():
        sirina = form.cleaned_data.get('sirina')
        visina = form.cleaned_data.get('visina')
        category = form.cleaned_data.get('category')
        roletne = form.cleaned_data.get('roletne')
        okapnice = form.cleaned_data.get('okapnice')
        materijal = form.cleaned_data.get('materijal')
        komore = form.cleaned_data.get('komore')
        krila = form.cleaned_data.get('krila')

        #Example 
        a = 20 + sirina
        b = 30 + visina 
        c = 50 + roletne
        ## I want to save those variables in database and load them after 
        ## in template



        form.save()

    context={'form':form}
    return render(request,'index.html',context)

标签: django

解决方案


推荐阅读