Problem with Python relative paths when deploying to Google App Engine Flexible

☆樱花仙子☆ 提交于 2021-01-28 12:49:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!