如何存储用户登录名? [英] How to store the name of user logged in?

查看:168
本文介绍了如何存储用户登录名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以自定义的形式存储当前登录到Django的用户的名字。在管理员中,我们可以通过编写modified_by = request.user.username来执行此操作,但是如何以自己的形式执行此操作?

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?

推荐答案

您可以定义Form的__init__方法来接受request参数,然后从您的视图传入,或者您可以使用线程本地人 hack。

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.

这篇关于如何存储用户登录名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆