Forums

Unable to setup my site.

Have this perfectly running on my local PC but Im unable to make it run here.

wsgi.pt:

from main import app as application

main.py:

from website import create_app
app = create_app()

initi.py (under website):

from dotenv import load_dotenv
from flask_migrate import Migrate
......

db = SQLAlchemy()
image_folder= os.getenv("UPLOAD_FOLDER")
ALLOWED_EXTENSIONS = os.getenv("ALLOWED_EXTENSIONS")
load_dotenv()


def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = os.getenv("APP_SECRET_KEY")
    app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("DATABASE_URL")
    db.init_app(app)
    migrate = Migrate(app, db)
    from .views import views
    from .auth import auth

    app.register_blueprint(views, url_prefix='/')
    app.register_blueprint(auth, url_prefix='/')

get error on my log:

2023-02-11 14:09:23,405: Error running WSGI application 2023-02-11 14:09:23,406: RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set. 2023-02-11 14:09:23,406: File "/var/www/...._pythonanywhere_com_wsgi.py", line 16, in <module> 2023-02-11 14:09:23,407: from main import app as application # noqa 2023-02-11 14:09:23,407: 2023-02-11 14:09:23,407: File "/home/.../main.py", line 3, in <module> 2023-02-11 14:09:23,407: app = create_app() 2023-02-11 14:09:23,407: 2023-02-11 14:09:23,408: File "/home/.../website/init.py", line 21, in create_app 2023-02-11 14:09:23,408: db.init_app(app) 2023-02-11 14:09:23,408: 2023-02-11 14:09:23,408: File "/home/.../venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 307, in init_app 2023-02-11 14:09:23,408: raise RuntimeError(

Any help is appreciated.

Many thanks

Normally I would expect the call to load_dotenv to specify where the file is that contains the environment variables; see this help page for the details.

Thanks.

I rewrote all the code not to include blueprints. I think is more something to do with that dont know why.

In fact my new code with:

from webforms import MemberForm,UserForm,LoginForm

load_dotenv()
db = SQLAlchemy()
app = Flask(__name__)

image_folder= os.getenv("UPLOAD_FOLDER")
ALLOWED_EXTENSIONS = os.getenv("ALLOWED_EXTENSIONS")
app.config['SECRET_KEY'] = os.getenv("APP_SECRET_KEY")
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("DATABASE_URL")

db.init_app(app)

is up and running so load_dotenv is not the issue.

But thanks for your suggestion.

Thanks

Might it be related to the working directory? I imagine that might have changed while you were refactoring. load_dotenv by default (I think) loads environment variables from the file .env in the working directory that your site's process is running with. That might not be the directory that you expect it to be -- it's defined on the "Web" page, and can be completely different to the directory containing your code.