On Thu, 2006-09-07 at 03:41 +0000, SmileyChris wrote: > When moving an app to a different project, I had to go through and fix > all the references to my project name in code. Is there a better way to > import my code? Currently I import like: > > from projectname.appname.models import Model > > It seems like this inhibits portability of apps somewhat. Perhaps there > could be some sort of "from django.conf import settings" for apps? >
Well, as far as I know, python's import is relative. So if you're in the module /home/gray/white.py and you say import blue it will first try to find blue.py in /home/gray, so design your imports carefully. Second, there's a hack I think I saw on the documentation site (in the comments), I use it in my urlconf, it goes like : _package = '.'.join(__name__.split('.')[:-1]) urlpatterns = patterns(_package+'.views', ...... which just assumes that it's loading views from the same directory as the urls.py file. This is because, a string is needed for urlpatters, a string to the full python path. Here we determine it at runtime. Hope this helps. /Marc DM --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers -~----------~----~----~----~------~----~------~--~---