Django pass object from view to next for processing

后端 未结 2 1518
小鲜肉
小鲜肉 2021-02-08 23:02

If you have 2 views, the first uses modelform that takes inputted information from the user (date of birth, name, phonenumber, etc), and the second uses this information to crea

2条回答
  •  我在风中等你
    2021-02-08 23:51

    One approach is to put the object into a session in your first view, which you could then retrieve from the request.session in the second view.

    def first_view(request):
        my_thing = {'foo' : 'bar'}
        request.session['my_thing'] = my_thing
        return render(request, 'some_template.html')
    
    def second_view(request):
        my_thing = request.session.get('my_thing', None)
        return render(request, 'some_other_template.html', {'my_thing' : my_thing})
    

提交回复
热议问题