On Aug 9, 11:22 am, Kejun He <printer...@gmail.com> wrote: > hi, > Ok, It is a good method to get the current user.
It's actually THE good method. > > But i just do maintain a django project, and i do not want to change the > template structure. > > And now, I have found a new method to resolve the problem. > > through a variable CURRENT_USER defined in settings.py to save the current > user in a view. > and get the current_user from settings.CURRENT_USER. How ? And does it really works ?-) (hint: whatever you might think, it's totally broken) > And i found a strange appearance. > > PART_ONE: > I defined a variable named CURRENT_USER > > and import the settings in a view like below: > > from gmadmin import settings ################## the gmadmin is the name > of the topo directory DONT import settings that way. ALWAYS use "from django.conf import settings" > > then assign request.user to settings.CURRENT_USER Question: what do you think will happen in a multithreaded environment ? > PART_TWO: > Get the settings.CURRENT_USER in a .py file > > the code: > import settings > user = settings.CURRENT_USER > > But it reported a problem: the settings.CURRENT_USER is None . > and the problem disappeared when i use "import settings" instead of "from > gmadmin import settings" on PART_ONE。 > > Could you talk about it? It would be better if you learned enough about Django and Python to find out by yourself - and why this approach will never work. In the meantime, save yourself some pain and do things the right way (IOW: do has Tom said). -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.