My File Directory:
app/
app.py
app/server/
views.py
I don’t get any import errors with views, but I am not able to URL route to Views – I can only do it from app.py – how can I fix this issue? I’ve been stuck on this for 6 hours.
Code from app.py – how I import views
sys.path.append(os.path.join(os.path.abspath('.'), 'server'))
import views
And my url routing seems fine, so I am not sure where the problem lies:
@app.route("/login/", methods=['GET', 'POST'])
def login():
doSomething()
I feel the problem is more to do with url routing than importing files though.
Try
from views import *instead ofimport views.Also, instead of doing
sys.path.append, add an empty file named__init__.pyto the server directory, and you should be able to do something likefrom server.views import *.Solution: Also make sure your view import is towards the bottom of your app file, below the app initialization and config and such.