I got a reply to this query after mistakenly emailing someone directly: On Mon, 2007-05-14 at 08:05 -0700, badger17 wrote: >> > > You need the second one because I suspect you are leaving off the >> > > "myproject" part of the import path somewhere inside your code. You >> > > could track those down and save yourself one path addition if you wanted >> > > to. > > > > I am somwhat confused on this point --- The Django docs make a bit > > point of Django apps being 'pluggable', ie you can take them and stick > > them in a new project and they should work, with the urls.py have > > specfic directives for this purpose. However unless you have your > > PythonPath variables setup to contain both directory levels as in the > > example by Char, you can't reference other apps within your current > > project. For example I downloaded the Django `tagging' app from Google > > Code, and this assumes it can do things like: > > > > import Tag from tagging.models > > > > Is there any 'correct' way for this to be done, the Django tutorial > > pages seem a bit self-contradictory on this point.
Everything you import must be on the Python path. So if you are going to import things as myproject.myapp.*, you need to have the directory containing myproject/ on your Python path. But if you are only going to import things as "from myapp ...", then you need myproject/ on your Pythonpath (but not it's parent, since you're not importing anything from the parent dir). Applications do not even need to be in "projects". The concept of a project is just a nice grouping for starting out with Django. In the above example, it looks like you would install the directory called "Tag/" somewhere on your Python path. Of course, this means you can install it anywhere you like and then modify your Python path to point to the directory holding Tag/. A lot of people (including me) have a directory containing apps that are installed somewhere on the system (we include that directory on our Python path) and our projects often import things from this app- holding directory. I have some "projects" that are basically a settings file, a home page template, and maybe a couple of specialised views, but most of the real work is done by other apps that are not under the project directory at all. As far as the tutorial being contradictory, or not all-inclusive, do remember that the tutorial is for people just starting out with Django. We cannot possibly go into every little detail in the tutorial or it would be about 3000 pages long. Once you are at the point where you understand the bigger picture, having worked through the tutorial, they should be able to see that they can place things anywhere they like on their Python path, since importing things is nothing special to Django -- it's all done by Python. Of course, if somebody is trying to learn Python and Django at the same time and so Python paths are a bit of a mystery, things will be harder. But we can't really accommodate that case too much in the tutorial, because then it would be 50% teaching things about Python that most of the audience already knows. We try to be as explicit as possible, but we have to leave the "learning how Python works" side of things up to others. 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 [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 -~----------~----~----~----~------~----~------~--~---

