Can a Python script use a Django database while not being in the same folder?
<p>I have a python application (which we'll call app) I'd like to have a web front for. The application has many files and it's important the folder tree structure stays the way it is.</p>

<p>I've built a Django project and put it in a folder named "Web" in the app's folder, so now the folder tree looks like so:</p>

<ul>
<li>[Data]</li>
<li>[Resources]</li>
<li>[Web]

<ul>
<li>[WebFront]

<ul>
<li>normal django app files</li>
</ul></li>
<li>[Web]

<ul>
<li><code>__init__.py</code></li>
<li>settings.py</li>
<li>urls.py</li>
<li>wsgi.py</li>
</ul></li>
<li><code>__init__.py</code></li>
<li>manage.py</li>
</ul></li>
<li>main.py</li>
</ul>

<p>Here's the code on the app's main.py:</p>

<pre><code>import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Web.Web.settings")
django.setup()
</code></pre>

<p>This code causes an exception on the <code>django.setup()</code> line as (I think) django does not find the project modules: <code>ImportError: No module named WebFront</code> (WebFront is the name of the django app)</p>

<p>I suspect this is caused because django runs in the directory of python app, and therefore cannot find the folder <code>WebFront</code> - Which should actually be <code>Web/WebFront</code></p>

<p>Can this be done? Or should I reverse the order and put the python app in the django app?</p>

<hr>

<p>This is not a duplicate of the following questions as the folder nesting causes a different problem (I think)</p>

<ul>
<li><a href="https://stackoverflow.com/questions/25537905/django-1-7-throws-django-core-exceptions-appregistrynotready-models-arent-load/26215548#26215548">Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren&#39;t loaded yet</a></li>
<li><a href="https://stackoverflow.com/questions/1381346/easiest-way-to-write-a-python-program-with-access-to-django-database-functionali">Easiest way to write a Python program with access to Django database functionality</a></li>
<li><a href="https://stackoverflow.com/questions/579511/using-only-the-db-part-of-django">Using only the DB part of Django</a></li>
</ul>