Hi Urukay, Thanks a lot, it works!
----- *YÁNG ChéngF**u(* *Unix Administrator * *Gameloft** ***-- Global Network Services (GNS)** ****** ***mailto:chengfu.y...@gameloft.com** **(** +86(10)8260-7820 Jabber:chengfu.y...@bei.gameloft.org urukay a écrit : > Don't know if i understand you right, but maybe this could help: > > in form: > class ContactForm(forms.Form): > > def __init__( self, user_choices_list, *args, **kwargs ): > super( ContactForm, self ).__init__( *args, **kwargs ) > self.fields['email'].choices = user_choices_list > > email = forms.ChoiceField() > > in view: > def contact(request): > variable_from_views=get_list_from_ldap(user_input_variable) > form = ContactForm(variable_from_views) > return render_to_response('contact_form.html', {'form': form}) > > hope it helps > > Radovan > > > > YANG ChengFu-2 wrote: > >> Hello, >> >> I'd like to import the variables from view to form, but after trying >> several ways, I failed. >> >> For example: user01 inputs his username/password(apache >> authentication) to login, then based on this username, function, >> get_list_from_ldap, will get a relative list from LDAP. Different >> username will have different lists. Then I'd variable_from_view >> can be used as choices of ChoiceField. >> >> Anyone knows how I can do it? >> >> Any comments will be welcome >> >> In from.py >> >> from django import forms >> >> class ContactForm(forms.Form): >> email = forms.ChoiceField(choices=variable_from_views) >> >> >> views.py >> from django.shortcuts import render_to_response >> from mysite.contact.forms import ContactForm >> >> def contact(request): >> variable_from_views=get_list_from_ldap(user_input_variable) >> form = ContactForm() >> return render_to_response('contact_form.html', {'form': form}) >> >> >> >> > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---