On Tue, Aug 9, 2011 at 5:54 PM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote:
> 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" > I test in my development server, and found that from django.conf import settings is to all client but import settings is to a singal one > > > > > then assign request.user to settings.CURRENT_USER > > Question: what do you think will happen in a multithreaded > environment ? > I just test it on my development server, and it could work normally when there are several users. And have not test it 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). > my method is not a normal way on django thanks for your suggestion, I will spend enough time to learned django, i am so new > > -- > 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.