Search code examples
pythonflaskhttp-status-code-404

Flask - 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'm completely new to Flask. As a beginner I'm trying to print 'Hello World' on a web page. When run this Flask application, the browser throwing me a 404 error. It says The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Here is my __init__.py :

from flask import Flask

app = Flask(__name__)

from app import app

My routes.py file:

from app import app

@app.route('/')
@app.route('/index')
def index():
    return "Hello, World!"

And my microApp.py file:

from app import app

Here is my working directory:

My Project/
  venv/
  app/
    __init__.py
    routes.py
  microApp.py

I set FLASK_APP = microApp.py and tried to run Flask. But the browser is throwing me an error.

Please anyone help me, I'm a noob. Thanks in advance.


Solution

  • When you are importing app that means your basically importing __init__.py file. The __init__.py files are modules that initialize the packages.modules So in your __init__.py file you importing again 'app'. Here you have to call 'routes'.