问题
I have simple Python app I'm trying to deploy to App Engine. The app runs perfectly in my local environment. I've been struggling for hours with absolute and relative paths. I have the following simple filter in the /utils folder, filters.py file:
from .. import app
@app.template_filter()
def nicedate(datestring):
datestring=datestring[:10]
return datestring
When running my app, I get the following error:
from .. import app
ValueError: attempted relative import beyond top-level package
That's strange, because I understand the . means "one level up" and I have the following project structure:
main.py
views.py
requirements.txt
app.yaml
util/
filters.py
templates/
static/
etc.
And the relative import with two dots works perfectly in my development environment.
So, filters.py are just one level down, and the .. is supposed to take me one level up.
However when I use only one dot, I get:
from . import app
ImportError: cannot import name 'app'
How should I do this import?
来源:https://stackoverflow.com/questions/56591614/problem-with-python-relative-paths-when-deploying-to-google-app-engine-flexible