Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想以自定义形式存储当前登录到 Django 的用户的名称。在管理员中,我们可以通过编写 modified_by=request.user.username 来做到这一点,但我如何以自己的形式做到这一点?
您可以定义表单的 __init__ 方法以接受“请求”参数,然后从您的视图中传递它,或者您可以使用线程本地化技巧。