title: How to import from __init__.py with Flask
body: <p>I have the following file structure for a Flask application:</p>
  
  <pre><code>myapplication/
    run.py
    myapplication/
      __init__.py
      views/
        __init__.py
        models.py
        ...
      templates/
      static/
  </code></pre>
  
  <p>And I have initialised the database in <code>myapplication/__init__.py</code> using SQLAlchemy. I want to import the database object in <code>models.py</code> though I'm unsure on how to do it.</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/22282316/python-how-to-import-from-an-init-py-file">this answer</a> and tried to import the database object from <code>myapplication/__init__.py</code> using relative imports like this:</p>
  
  <pre><code>from ... import db
  </code></pre>
  
  <p>but I receive this error: <code>ValueError: Attempted relative import in non-package</code>.</p>
  
  <p>So how to I get to the database object in <code>myapplication/__init__.py</code> for <code>models.py</code>? Thanks.</p>