skip to Main Content

I followed along with a youtube tutorial learning how to create a Flask website, and it works perfectly on my local machine.

I created a subdomain in my cPanel and used the ‘setup Python app’ wizard to create the app, it worked. So I uploaded the Flask app I made to the server and installed all the requirements. went to the site and this is what I get:
Website

The home page is displayed (it shouldn’t be, it should direct you to the login page) and it seems to be overlapping with the navbar. all the links in the navbar return a 500 error, with no log in the error reports on the cPanel.

I’ve been trying to get it to work for 3 days I can’t get it to work.

File tree:
File Tree

The Website folder holds all the files and templates

run.py:

from Website import create_app

app = create_app()

if __name__ == '__main__':
    app.run()

passenger_wsgi.py:

import imp
import os
import sys


sys.path.insert(0, os.path.dirname(__file__))

wsgi = imp.load_source('wsgi', 'run.py')
application = wsgi.app

Website.init.py:

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 Website.config import Config



db = SQLAlchemy()
bcrypt = Bcrypt()
login_manager = LoginManager()
login_manager.login_view = 'users.login'
login_manager.login_message_category = 'info'

mail = Mail()




def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)

    from Website.users.routes import users
    from Website.posts.routes import posts
    from Website.main.routes import main
    from Website.errors.handlers import errors
    from Website.booking.routes import booking
    app.register_blueprint(users)
    app.register_blueprint(posts)
    app.register_blueprint(main)
    app.register_blueprint(errors)
    app.register_blueprint(booking)
    return app

Can anyone please help figure out what I’ve done wrong?

Problem seems to be with URL_for() command to route links

2

Answers


  1. Chosen as BEST ANSWER

    Answering my own question.

    The problem was with the url_for() command to route the pages together. Not sure what the problem was but it wasn't looking in the right place. I fixed it by going to the .htaccess file and adding

    RewriteEngine On 
    RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]
    

    no more 500 errors and it could find the css file.


    1. The home page is displayed (it shouldn’t be, it should direct you to the login page) <

    Could be because you need to add the login decorator to the route for the home page url. could also be because you’re already logged in (you logged in to upload the files to your cpanel/hosting server and haven’t yet logged out; you should try opening your app in a different browser or private window in same browser)

    1. it seems to be overlapping with the navbar. <

    This is usually due to path issues i.e. your app is not seeing the correct path for your static files (any stylesheets, images, etc). To confirm, copy the full url to your stylesheet and try to open it in a new browser tab. If you get a 404, that tells you your path is incorrect

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search