samedi 5 juin 2021

Appplication Error on heroku python flask app

Iam trying to deploy my first website to heroku web host, but i keep getting this "application error" when i try to open the page, ive looked at some other stack overflow solotuion which was to change the PORT to 5000 and 8000 but still same issue, i can provide my code and what ive done so far below, hope you can help, thanks.

Did this all first

# Set up virtual environment for python (git bash)
1. cd C:\\Users\\mathe\\OneDrive\\Documents\\Python\\Flask-Framework\\flaskapplication
2. pip3 install -U pip virtualenv
3. virtualenv --system-site-packages -p python ./venv
4. source .\\venv\\Scripts\\activate

# Preparing our application to be hosted
1. pip install gunicorn
2. Make a Procfile
3. Make sure to have requirements.txt file
4. heroku login
5. heroku create
6. heroku rename mathewsjoy // This renames your website
7. git push heroku main // commits all of your app to the heroku web app

PROCFILE

web: gunicorn -b :$PORT app:run

MY RUN.PY FILE which works when i host on my local machine by doing python run.py

from app import create_app
import os

# Call the create_app fucntion in __init__.py
app = create_app()

# Run the app in debug mode so we dont have to set environment variable
# and close the app everytime a change it made
if __name__ == "__main__":
    PORT = int(os.environ.get('PORT', 8000))
    app.run(host='0.0.0.0', port=PORT, debug=False)

CREATE_APP() function above is in this config.py file

# Import neccassery libraries
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from app.config import Config


db = SQLAlchemy() # Make a database
bcrypt = Bcrypt() # Make a encryption for pass
login_manager = LoginManager() # Used to manage site logins
login_manager.login_view = 'users.login' # Similar to url_for
login_manager.login_message_category = 'info'
mail = Mail()


def create_app(config_class = Config):
    app = Flask(__name__)
    app.config.from_object(config_class) # Apply all configuration in the config.py file to the app
    
    # Pass in app for our extensions above this class
    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)
    
    
    # import 'users' is the blueprint instance we made at start of users.routes files
    from app.users.routes import users 
    from app.posts.routes import posts
    from app.main.routes import main
    from app.errors.handlers import errors
    # Need to reigster our blueprint before we can use it in our actual app
    # We also needed to change all url_for to have the blueprint in front e.g
    # url_for('home') -> url_for('main.home')
    app.register_blueprint(users)
    app.register_blueprint(posts)
    app.register_blueprint(main)
    app.register_blueprint(errors)
    
    return app



Aucun commentaire:

Enregistrer un commentaire