In the official Quickstart, it's recommended to use __name__
when using a single module:
- ... If you are using a single module (as in this example), you should use
__name__
because depending on if it’s started as application or imported as module the name will be different ('__main__'
versus the actual import name). ...
However, in their API document, hardcoding is recommended when my application is a package:
So it’s important what you provide there. If you are using a single module,
__name__
is always the correct value. If you however are using a package, it’s usually recommended to hardcode the name of your package there.
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 Flask
get when it receives a __main__
as its first parameter? I can't see how this can make it easier for Flask to find the resources...