How to store the name of user logged in?

无人久伴 提交于 2019-12-23 04:21:58

问题


I want to store the name of the user who is currently logged into Django in a custom form. In the admin we can do so by writing modified_by=request.user.username, but how do I do this in my own form?


回答1:


You can either define the __init__ method of your Form to accept a "request" parameter, and then pass that in from your view, or you can use the thread-locals hack.



来源:https://stackoverflow.com/questions/939157/how-to-store-the-name-of-user-logged-in

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