How do you pass or share variables between django views?

前端 未结 3 1350
抹茶落季
抹茶落季 2020-12-03 15:33

I\'m kind of lost as to how to do this:

I have some chained select boxes, with one select box per view. Each choice should be saved so that a query is built up. At

相关标签:
3条回答
  • 2020-12-03 15:47

    There are many ways... in the view to template... put the variables in hidden fields in the forms. So when you "submit" in the subsequent forms... the values are then contained in the following request.POST.get().

    Of course you can also store the various data elements in a DB table (disk or ram) between views... using the session_id as the key into the datastore. (not recommended for load balanced systems).

    And my least favorite is cookies. (see the APIs for how to store in cookies)

    UPDATE: Sorry there are no code examples here... the docs are pretty easy to read. There is also a djangosnippets website that you use to look up example code.

    0 讨论(0)
  • 2020-12-03 15:48

    Put the values to hold into the session.

    0 讨论(0)
  • 2020-12-03 15:57

    You can store such information in session as Ignacio Vazquez-Abrams said or use django-flash - (django-flash usage)

    0 讨论(0)
提交回复
热议问题