When I first learned how to use Django, passing variables was a constant source of confusion. With some practice, I got a better handle on the basics. You pass variables from the view to the template via context. And you pass variables from the template to the view via :
That's all I needed at that point in time anyway. I've just discovered there are more ways of passing them. One in particular caught my eye, passing it via sessions.
- the URL
- POST(when submitting forms, for instance)
- and query parameters.
That's all I needed at that point in time anyway. I've just discovered there are more ways of passing them. One in particular caught my eye, passing it via sessions.
It's so easy to use. Once you've set it in your view, you can access it anywhere in your project. I imagine this is not something you would want to do with sensitive information though? I might be wrong of course. But it's definitely interesting to learn a new way to pass around variables.
Comments
Post a Comment