hi, I will do as your method thanks for your reply
regards, kejun On Tue, Aug 9, 2011 at 5:56 PM, Tom Evans <tevans...@googlemail.com> wrote: > On Tue, Aug 9, 2011 at 10:22 AM, Kejun He <printer...@gmail.com> wrote: > > hi, > > Ok, It is a good method to get the current user. I am sorry for that. > > > > 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. > > > > thanks for your reply. > > > > > > 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 > > > > then assign request.user to settings.CURRENT_USER > > > > 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? > > > > regards, > > kejun > > > > You should not do this. > > > https://docs.djangoproject.com/en/1.3/topics/settings/#altering-settings-at-runtime > > If a function needs a user object, pass it a user object as an > argument. Using globals is a clear sign that you haven't understood > the problem. Don't do it. I gave you a precise way of achieving this > without futzing around with anti-patterns. > > Cheers > > Tom > > -- > 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. > > -- 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.