Type-casting of session object in python, django
I would like to ask something about tyoe casting in python, Django.
I have a CompanyReview
object in session request.session['review_company_review']
and I would like to get this object.
I have written the code below but I consider there should be a better way.
cr = CompanyReview()
cr = request.session['review_company_review']
Could you g开发者_开发百科ive me any idea how I can cast my session object to companyreview object ?
PS: I try to do cr = ComapnyReview(request.session['review_company_review'])
but it didn't work.
Thanks
You don't need any type-casting in Python.
If you have saved that object to session doing like request.session['review_company_review'] = some_company_review_object
, to retrieve that object you can just do:
cr = request.session['review_company_review']
精彩评论