Hi It seems your problem with dlist_choice is caused by an incorrect you of global vars. I've not used globals much myself, but I believe that you don't import them, but instead in every function that needs them do a global var_name.
the other traceback seems irrelevant, but the problem you that you haven't defined/imported choice in ....ChoiceField(choices = choice, ...) ~Jakob On 13 Maj, 08:51, Yang <[email protected]> wrote: > Hi guys, > > I am a beginner of Django, a problem has been unsolved for a long > time, can you help me. > > I have a file forms.py: > > from django import forms > from views import dllist_choice > class DLForm(forms.Form): > distribution_list=forms.ChoiceField > (choices=dllist_choice,widget=forms.Select(attrs={'size':'20'})) > > class GroupMemberForm(forms.Form): > Members = forms.ChoiceField(widget=forms.Select(attrs= > {'size':'20'})) > > and views.py looks like: > from django.shortcuts import render_to_response > from django.contrib.sessions.models import Session > from forms import DLForm, GroupMemberForm > from adldap import adldap > import ldap.dn > options={ > 'account_suffix': '[email protected]', > 'base_dn' : 'DC=example,DC=org', > 'hostport' : "ldap://bei-dc01.gameloft.org:3268", > 'ad_username' : "CN=wanng lin,OU=User,DC=example,DC=org", > 'ad_password' : 'xxxxxxxx', > 'real_primarygroup' :True, > 'use_ssl' :True, > # 'recursive_grups' :True} > > ad = adldap(options) > dllist_choice=() > > def get_dl_list(request): > global dllist_choice > choice = ad.list_managed_dl('[email protected]') > dllist_choice=choice > form1 = DLForm() > return render_to_response('dl_form.html', {'form': form1}) > > ChoiceField.choices come from LDAP databases, can someone know how to > pass dllist_choice in view to the form. I have tried to import as a > variable, but I got error: > > ImportError at / > > cannot import name dllist_choice > > Request Method: GET > Request URL: http://poplar.bei.gameloft.org:8000/ > Exception Type: ImportError > Exception Value: > > cannot import name dllist_choice > > Exception Location: /home/ychengfu/dl/../dl/forms.py in <module>, > line 2 > Python Executable: /usr/bin/python > Python Version: 2.5.2 > Python Path: ['/home/ychengfu/dl', '/usr/lib/python2.5', '/usr/lib/ > python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/ > python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/ > usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/ > Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/ > site-packages/gst-0.10', '/var/lib/python-support/python2.5', '/usr/ > lib/python2.5/site-packages/gtk-2.0', '/var/lib/python-support/ > python2.5/gtk-2.0', '/usr/lib/python2.5/site-packages/wx-2.6-gtk2- > unicode'] > Server time: Wed, 13 May 2009 01:49:58 -0500 > > Traceback Switch back to interactive view > Environment: > > Request Method: GET > Request URL:http://poplar.bei.gameloft.org:8000/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" > in get_response > 77. request.path_info) > File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in > resolve > 179. for pattern in self.urlconf_module.urlpatterns: > File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in > _get_urlconf_module > 198. self._urlconf_module = __import__ > (self.urlconf_name, {}, {}, ['']) > File "/home/ychengfu/dl/../dl/urls.py" in <module> > 6. from views import get_dl_list, show_users > File "/home/ychengfu/dl/../dl/views.py" in <module> > 3. from dl.forms import DLForm, GroupMemberForm > File "/home/ychengfu/dl/../dl/forms.py" in <module> > 7. class DLForm(forms.Form): > File "/home/ychengfu/dl/../dl/forms.py" in DLForm > 9. distribution_list=forms.ChoiceField(choices = choice, > widget=forms.Select(attrs={'size':'20'})) > > Exception Type: NameError at / > Exception Value: name 'choice' is not defined > > Any comment will be appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

