Flask('application') versus Flask(__name__)
<p>In the official <a href="http://flask.pocoo.org/docs/0.11/quickstart/#a-minimal-application" rel="nofollow">Quickstart</a>, it's recommended to use <code>__name__</code> when using a single <strong>module</strong>:</p>

<blockquote>
  <ol start="2">
  <li>... If you are using a single module (as in this example), you should use <code>__name__</code> because depending on if itâs started as
  application or imported as module the name will be different
  (<code>'__main__'</code> versus the actual import name). ...</li>
  </ol>
</blockquote>

<p>However, in their <a href="http://flask.pocoo.org/docs/0.11/api/#application-object" rel="nofollow">API document</a>, hardcoding is recommended when my application is a <strong>package</strong>:</p>

<blockquote>
  <p>So itâs important what you provide there. If you are using a single
  module, <code>__name__</code> is always the correct value. If you however are
  using a package, itâs usually recommended to hardcode the name of your
  package there.</p>
</blockquote>

<p>I can understand why it's better to hardcode the name of my package, but why not hardcoding the name of a single module? Or, in other words, what information can <code>Flask</code> get when it receives a <code>__main__</code> as its first parameter? I can't see how this can make it easier for Flask to find the resources...</p>

<p><code>__name__</code> is just a convenient way to get the import name of the place the app is defined.  Flask uses the import name to know where to look up resources, templates, static files, instance folder, etc.  When using a package, if you define your app in <code>__init__.py</code> then the <code>__name__</code> will still point at the "correct" place relative to where the resources are.  However, if you define it elsewhere, such as <code>mypackage/app.py</code>, then using <code>__name__</code> would tell Flask to look for resources relative to <code>mypackage.app</code> instead of <code>mypackage</code>.</p>

<p>Using <code>__name__</code> isn't orthogonal to "hardcoding", it's just a shortcut to using the name of the package.  And there's also no reason to say that the name <em>should</em> be the base package, it's entirely up to your project structure.</p>

python flask import module package