title: django project directory structure and the python path
body: <p>I am trying to get the best possible set up for developing my django project from the start and I'm having trouble getting everything to play nicely in the directory structure. I have set up virtualenv's (env in this example) so that I can deploy a clean empty python environment for every django project.</p>
  
  <p>The basic structure is as follows:</p>
  
  <pre><code>/env/
      /bin
      /db         &lt;--- Django DB
      /downloads
      /lib
      /static     &lt;--- Where css/imgs/js etc is served from
      /project/   &lt;--- Django root
              /__init__.py
              /settings.py
              /manage.py
              /appsfolder/
                   /appname/
                         /__init__.py
                         /models/
                                /__init__.py
                                /somemodel.py
                         /urls/
                               /__init__.py
                               /someurl.py
                         /views/
                               /__init__.py
                               /someview.py
  </code></pre>
  
  <p>This is the basic layout; I want each project to have a directory for applications, and in each application have a separate folder for models, view and urls. </p>
  
  <p>The problem I am having is with the python path and how the modules are handled. </p>
  
  <p>Within an application, I don't want to have to refer to the project when importing models i.e I should be using :</p>
  
  <pre><code>import appname.models.modelname
  </code></pre>
  
  <p>not:</p>
  
  <pre><code>import projectname.models.modelname
  </code></pre>
  
  <p>to help reusablility</p>
  
  <p>In the models directory, I have the following <strong>init</strong>.py</p>
  
  <pre><code>from model1 import ModelName1
  from model2 import ModelName2
  from model3 import ModelName3
  
  __all__ = ['ModelName1', 'ModelName2', 'ModelName3']
  </code></pre>
  
  <p>But when I try to use a separate url file (in /appname/urls/urlfile.py) and import the models like the following:</p>
  
  <pre><code>from appname.models.somemodel import ModelName
  </code></pre>
  
  <p>I get a "module not found" error. </p>
  
  <p>while: </p>
  
  <pre><code>from appsfolder.appname.models.somemodel import ModelName
  </code></pre>
  
  <p>works ok</p>
  
  <p>I presume this is because the application is not directly on the python path, instead it is in a subfolder called appsfolder,  but I'm not sure how to go about fixing this, while keeping everything reuseable and relative. </p>
  
  <p>I know one solution is to put all apps directly on the python path under site-packages, but I don't really like this idea, as I think that the applications should be in the project if you are using virtualenv's</p>