On Mon, Jun 2, 2008 at 9:06 AM, David.D <[EMAIL PROTECTED]> wrote: > views.py > ====== > def model_form(request, model_name): > form_class = __import__('products.models.%sForm'%model_name) > form = form_class() > ... > > model_name is a string
Unless you really grok how __import__() works, it's often best to avoid it. Here's an alternative solution:: import products.models as product_models def model_form(request, model_name): return getattr(product_models, '%sForm' % model_name)() -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---