Forums

404 Not Found - Again

New to PythonAnywhere and having issues with URL being found. Have read and tried the proposals to the many other posts on this subject, but nothing seems to fix the problem. My best understanding is that it is partially because app.run() is being activated. My other thoughts are that the main.py is not the correct version on my server. These are purely guesses on my part, because I am very new to PythonAnywhere. The below is from the server log.

2023-05-17 13:56:41 Set PythonHome to /home/dktodd/.virtualenvs/venv

2023-05-17 13:56:41 * Python threads support is disabled. You can enable it with --enable-threads *

2023-05-17 13:56:41 Python main interpreter initialized at 0x55d6651e8e70

2023-05-17 13:56:41 your server socket listen backlog is limited to 100 connections

2023-05-17 13:56:41 your mercy for graceful operations on workers is 60 seconds

2023-05-17 13:56:41 setting request body buffering size to 65536 bytes

2023-05-17 13:56:41 mapped 501384 bytes (489 KB) for 2 cores

2023-05-17 13:56:41 *** Operational MODE: preforking ***

2023-05-17 13:56:41 initialized 54 metrics

2023-05-17 13:56:41 WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x55d6651e8e70 pid: 1 (default app)

2023-05-17 13:56:41 *** uWSGI is running in multiple interpreter mode ***

2023-05-17 13:56:41 gracefully (RE)spawned uWSGI master process (pid: 1)

2023-05-17 13:56:41 spawned uWSGI worker 1 (pid: 2, cores: 1)

2023-05-17 13:56:41 spawned uWSGI worker 2 (pid: 3, cores: 1)

2023-05-17 13:56:41 metrics collector thread started

2023-05-17 13:56:41 spawned 2 offload threads for uWSGI worker 2

2023-05-17 13:56:41 spawned 2 offload threads for uWSGI worker 1

2023-05-17 13:56:48 announcing my loyalty to the Emperor...

my flask_app.py

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://dktodd:PSWD@dktodd.mysql.pythonanywhere-services.com:3306/Data$base'
app.config["SQLALCHEMY_POOL_RECYCLE"] = 299
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)

def create_app():
    if not path.exists('/' + DB_NAME):
        with app.app_context():
            db.create_all()
    else:
        print('Database not Connected.', DB_NAME)

if __name__ == "__main__":
    create_app()
    if 'liveconsole' not in gethostname():
        app.debug = False
        app.run(debug=True, use_reloader=False, port="3306")

my wsgi.py

import sys

path = '/home/dktodd/.virtualenvs/venv/'
path = "green-liveconsole11"
if path not in sys.path:
    #sys.path.append(path)
    sys.path.insert(0, path)

from flask_app import app as application

Any help you can provide to help to deploy to the web will be much appreciated.

additional code.

auth.py which is imported and called from flask_app.py

@auth.route('/login/', methods=['GET', 'POST'])
def login():
    form6=SignupForm()
    return render_template("login.html")

views.py is also imported and called from flask_app.py

@views.route('/', methods=['GET', 'POST'])
@login_required
def home():
    form4 = NumTablesForm()
    return render_template("home.html")

None of the code in the if __name__ == "__main__": is executed in a web app. That is only run when the file is directly run.

Thank you for your response. Does that mean that my create_app() function is not running? My understanding based on the many posts on this forum and elsewhere is that the "404 Not Found..." is cause by the WSGI not running? How can I confirm the WSGI file is running as it is suppose to? Is the WSGI code correct?

Thank you for any additional assistance you can provide.

Never mind on the last questions. I think I figured it out. Thank you.

No problem -- glad to hear you solved that.