folder structure
.
├── myapp
│ ├── api
│ │ └── routes.py
│ ├── app.py
│ |
│ └── site
│ └── routes.py
app.py is in myapp folder outside of api folder and site folder
api/routes.py
from flask import Blueprint
api = Blueprint('api',__name__,url_prefix='api')
@api.route('/userlist/')
def user():
return { 1: 'user1', 2:'user2'}
site/routes.py
from flask import Blueprint
site = Blueprint('site',__name__)
@site.route('/')
def index():
return 'Welcome to the Home page'
app.py
from flask import Flask
from .site.routes import site
from .api.routes import api
def create_app():
app = Flask(__name__)
app.register_blueprint(api)
app.register_blueprint(site)
return app
i got this error while running flask application using 'flask run' command in terminal
Traceback (most recent call last):
File "app.py", line 2, in <module>
from .site.routes import site
ImportError: attempted relative import with no known parent package
i don't understand how to solve this problem. thanks in advance :)