1

I am trying to import my app from app.py file into my manage.py file. When I run the command python manage.py create_db I get the error:

Usage: manage.py create_db [OPTIONS] Try 'manage.py create_db --help' for help.

Error: module 'src' has no attribute 'app.py'

I have tried:

import src.app

from .src import app

from src import app

from src.app import app

my file structure is

backend/
   src/
     __init__.py
     app.py
     config.py
   manage.py
   entrypoint.sh

Here is my manage.py file:

from flask.cli import FlaskGroup

import src.app
from src.models import User, Session, engine, Base

cli = FlaskGroup(src.app.app)

# if needed, generate database schema
session = Session()

@cli.command("create_db")
def create_db():
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

@cli.command("seed_db")
def seed_db():
    session.add(User(email="asearle@g.clemson.edu",first_name="Adrian",last_name="Searles",username="asearle",password="Pspgame12"))
    session.commit()


if __name__ == "__main__":
    cli()
buddy
  • 21
  • 4

1 Answers1

0

Try adding empty __init__.py in src directory. It makes python treat it as a module:

https://stackoverflow.com/a/448279/11298974

yjay
  • 942
  • 4
  • 11
  • Hi yjay, Thanks for the input. I actually have an __init__.py. I forgot to add that to the project structure. I'll edit it. – buddy Feb 17 '22 at 01:40