Monday, 15 September 2014

Flask Bug on Python 3.4? Development server can't run if app contains relative imports -


According to the design, Python 3 is a module that relates relative to a script. The attempt to do this causes the following error:

  $ python mypackage / run.py [Traceback ...] SystemEire: Parental module '' not loaded, not importing relative Can  

be the solution to open the module with python -m mypackage.run instead of more familiar python mypackage / run.py .

In the flask, later it is how a general development server runs. However, the flask development server instantly provokes the process of a child that reloads the code (and later the code is reloaded when switching to the disk).

The result of this is:

  $ Python -m mypackage.run * http: //127.0.0.1.1000/ * running on * reloader [... traceback ...] SystemRear: Parental module '' is not loaded, can not import relative.  

So now the server starts well, but children The process improperly reloads the code.

This is probably the way the reloador works if you are doing something unexpectedly, such as the app If you are calling the internal module directly to run, it is a habit to mess with the Python path.

run outside of its project is completely useful in development anyway, because in the production deployment the application will be used directly instead of the dev server.

  / my_project / /run.py / my_package / /__init__.py / my_module on the Python path by the  my_project  directory (or else  my_project ) 

execute run.py ). It will be very easy, like something:

  my_project_pkg import app  
from app.run (debug = true)

No comments:

Post a Comment