get request data in Django form

前端 未结 4 1429
有刺的猬
有刺的猬 2020-11-28 23:11

Is it possible to get request.user data in a form class? I want to clean an email address to make sure that it\'s unique, but if it\'s the current users email address then

4条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 23:31

    Not that I'm aware of. One way to handle this is have your Form class's __init__ take an optional email parameter, which it can store as an attribute. If supplied at form creation time, it can use that during validation for the comparison you're interested in.

提交回复
热议问题