Forums

No error logs, except 404 Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

I have addressed all errors that appeared on the errors log file and now the server runs with no errors.

GET request appears on the access log when I open the website url.

My views function normally on my localhost.

I am using the default WSGI configuration file for flask.

The file "init.py" where my app is located looks like below:

from flask import Flask
from flask_login import LoginManager
from events import socketio, users
import os


app = Flask(__name__)
app.secret_key = '1234'
app.app_context().push()
file_path = os.path.abspath(os.getcwd())+"\database\database.db"
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + file_path
app.secret_key = 'e101fde772e201928228'
login_manager = LoginManager(app)
login_manager.login_view = "login"
login_manager.login_message = "You need to log in to perform this action"
login_manager.login_message_category = "invalid-notif"
socketio.init_app(app)

Any help is greatly appreciated.

At the first glance, I think that the file_path will not work, as on Linux you should use / as the path delimiter.

@pafk Thank you for the reply. I have fixed the path delimiter but the 404 issue remains.

404 just means you do not have a view for the path that you're trying to access. Make sure that you've defined a view for the path and then you will not get a 404 on that path.

I have tried accessing only paths that I've defined a view for, but they all give a 404.

Here are two views in my python files.

@app.route("/")
def home():
    page = request.args.get("page", type=int)
    per_page = session.get("per_page") or 6
    posts_paginated = Post.query.order_by(Post.date_posted.desc()).paginate(per_page=per_page, page=page)
    if page:    
        posts_paginated.page = min(posts_paginated.pages, page)
    return render_template("index.html", posts_paginated=posts_paginated)

@app.route("/members")
def members():
    members = User.query.all()
    return render_template("members.html", members=members)

How and where are you defining those view functions? I don't see them in the init.py file that you provided above, and there's nothing there that looks like it would be importing them.

The views are defined in a main.py file that imports app and socketio from init.py. It's also where the app is run:

if __name__ == "__main__":
    socketio.run( app, host="0.0.0.0",allow_unsafe_werkzeug=True)

When you set up a website on PythonAnywhere, all it knows about your code is what is referenced from the file that you import in your WSGI file. So if your file "init.py" is the one imported there, then only the code in that file will run.