Thanks for this explanation, it makes it a bit clearer. But you say: "If you are running the dev-server", does that mean it won't work on a deployment server? Should I from the start use the Djangobook way in this case or leave the mysite out?
Regards, antoine On Jul 10, 5:31 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Wed, 2008-07-09 at 13:56 -0700, Antoine De Groote wrote: > > Hello, > > > this is my first post on this group. I just started using Django > > yesterday, reading throuhg the online Django Book > > (www.djangobook.com). > > > In chapter 3, for the URLconf, the authors put: > > > from django.conf.urls.defaults import * > > from mysite.views import current_datetime > > > urlpatterns = patterns('', > > (r'^time/$', current_datetime), > > ) > > > mysite is the root directory of the project and the files all reside > > within this folder. > > > I don't understand why they use: > > from mysite.views import current_datetime > > instead of > > from views import current_datetime > > > Both work, but I don't see why. The mysite directory is on the python > > path, not its parent. Why is it possible at all to write from > > mysite.views ... ? Is this handled internally by python? > > If you are running the dev-server (via "manage.py runserver"), manage.py > will automatically put the parent of the current directory into the > Python path. This is for the convenience of beginners. However, the net > effect is often to cause confusion down the road when those same people > don't realise that this is actually special behaviour and not something > Python does by default. You've caught the discrepancy, which is a safer > position to be in (you realise it's unusual). > > As a general rule, it's a little more portable to not use the project > name in imports, although if the views file lives in the project > directory it doesn't make a lot of difference. Many people just write > Django "apps", so a "project" becomes a collection of apps, plus a > settings file plus a root URL configuration file. But if you're putting > other stuff into that project directory, things are a little different. > > Just keep in mind that the Django book is an introduction to Django. > It's not going to take you from zero to 100 covering every single thing, > since it's not a 17 volume set. So it doesn't give bad advice, but it's > always possible to do things differently sometimes (and, just to be > certain, it almost always gives very, very good advice. It doesn't cut > corners). > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---