'Flask package structure, where do I properly place my API files?
Here is my current setup and it works, but this will bulk up the init file. How should I structure this so that my API is in its own folders and runs correctly? When I put testapi.py on the same level as run.py I couldn't get any models to import.
├── my_frame
│ ├── __init__.py
│ ├── forms.py
│ ├── models.py
│ ├── routes.py
│ ├── site.db
│ ├── static
│ ├── templates
│ └── testapi.py
├── run.py
└── venv
init.py
import os
from flask import Flask
from flask_restful import Api, Resource
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
#app config, db, encryption, loginmanager
app = Flask(__name__)
app.config['SECRET_KEY'] =
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
#app API
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {"data": "Hello World"}
api.add_resource(HelloWorld,"/helloworld")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
