问题
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