4

我正在开发一个应用程序,它的结构看起来与

facebook/
         __init__.py
         feed/
             __init__.py
             models.py
             business.py
             views.py
         chat/
             __init__.py
             models.py
             business.py
             views.py

facebook.__init__.py的是

from flask import Flask
app = Flask(__name__)
import feed.views
import chat.views

facebook.runserver.py的是

from . import app
app.run(debug=True)

feed.views.py的是

from .. import app

@app.route('/hello')
def hello():
    return 'hello world'

chat.views.py的是

from .. import app

@app.route('/chat')
def chat():
    return 'Let's chat'

当我尝试运行此应用程序时python runserver.py,我看到错误为

Traceback (most recent call last):
  File "facebook/runserver.py", line 1, in <module>
    from . import app
ValueError: Attempted relative import in non-package

我该如何解决?

4

1 回答 1

6

put your runserver.py outside of the facebook folder and make its content as:

from facebook import app
app.run(debug=True)
于 2013-03-23T07:54:12.323 回答