Django: Save cleaned_data in a session effectively

删除回忆录丶 提交于 2019-12-10 21:30:27

问题


In one of my forms, I am processing the form data and save it in a session variable.

So when I run

if locationForm.is_valid():

I execute

request.session['streetNumber'] = locationForm.cleaned_data['streetNumber']
request.session['postalCode'] = locationForm.cleaned_data['postalCode']
request.session['state'] = locationForm.cleaned_data['state']
request.session['country'] = locationForm.cleaned_data['country']

But this seems very inefficient. I have tried

request.session = locationForm.cleaned_data

but it does not seem to work.

  • Is there any better way of storing all cleaned_data information in a session variable?
  • Are there security concerns I should be aware off?

回答1:


what about

for k, v in locationform.cleaned_data.iteritems():
  session[ k ] = v


来源:https://stackoverflow.com/questions/8454000/django-save-cleaned-data-in-a-session-effectively

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!