Home > Software design >  Unable to view flask app -- network error 404 on localhost
Unable to view flask app -- network error 404 on localhost

Time:02-26

I see this issue posted alot...but no solutions thus far have worked for me (sorry about the repost).

PROBLEM I'm trying to run flask on my windows10 machine, and am unable to load a simple hello.py without a 404 error.

DEBUGGER The debugger is working for syntax errors (I can see the lines from hello.py file in my browser if I break the syntax in the file...but I'm getting no help on the 404 if the py file doesn't contain errors. The terminal also detects changes to the file it's supposed to load on the screen.

(I take it this means that the venv is set up properly, and the issue lies in the network handlers on windows..)

Things I've done I've tried.

  1. Disabling all the firewalls
  2. Restarting the machine (countless times)
  3. netstat -aon to confirm my ports are being used by another service.
  4. Uninstalling and reinstalling python
  5. Setting up new venvs on different drives on my machine
  6. allowing all permissions in windows for all users and guests prior to creating the virtual environment.
  7. installing xampp and setting up ports for apache => flask run --port:PORT
  8. Uninstalling xampp
  9. sitting and crying in the corner of the shower with water running on my face

Code for hello.py

'''

from flask import Flask
from werkzeug.debug import DebuggedApplication

app = Flask(__name__)

app.route('/')
def index():
    return '<h1>hello world</h1>'



if __name__ =='__main__':
    app.run(host='localhost', port=5000, debug=True)

'''

File Tree

_pycache_
Include
Lib
Scripts
hello.py
pip-selfcheck.json
pyvenv.cfg

CodePudding user response:

You did not wrote the decorator for the index Function the right way.

This is a fixed Version who should work:

@app.route('/')
def index():
    return '<h1>hello world</h1>'

The @ symbol is needed to tell python that this function was decorated with the route.

  • Related