Alexis Bellido wrote: > I'm reading the Django book and playing with the 'mysite' test site, > in many parts I've noticed something like this in views.py: > > from mysite.models import Event, BlogEntry > > I was wondering if it's good practice using 'mysite.models' (which > seems to be an 'absolute path' for importing) or if it would be better > using just: > > from models import Event, BlogEntry > > (which seems to be a 'relative path' because usually views.py is in > the same directory than models.py). > > Could somebody explain a little about the best way to do the imports?
I believe, nay I know, relative imports are evil. It's easy to get confused which models "from models" represents. Esp when/if there are multiple models.py in your Python path. Maybe not with models.py but it happens, believe me I've wasted too much time on it. Just don't do it. But it's also wrong to tie apps to a particular site. This is bad: from mysite.myapp.models import Your models views, etc should be under myapp not mysite. and the directory(ies) were all your apps are should be on python path. Then from myapp.models import blah. For maximun portability and flexibility mysite should not appear in any import. For my projects I create a directory like /web/www.example.com/python, I put that directory on the Python Path and put all my apps plus settings.py file in that directory. some reading http://www.b-list.org/weblog/2007/nov/09/projects/ and http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/ -- Norman J. Harman Jr. Senior Web Specialist, Austin American-Statesman ___________________________________________________________________________ It's August! Keep your cool with the Statesman. Check out our hot deals in print and online for back-to-school savings and more! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---