Home > Mobile >  Not found The requested URL was not found on the server. If you entered the URL manually please chec
Not found The requested URL was not found on the server. If you entered the URL manually please chec

Time:05-25

I have a code like this:

from flask import Flask, jsonify
app = Flask(__name__)
app.run(port=5000)

clients = [
    {
      'imie': 'Jan',
      'nazwisko': 'Kowalski',
      'produkt': 'Karta podarunkowa Media Expert',
      'wartość': 100,
      'ilość': 2,
    }
]


@app.route('/')
def get_clients():
    return jsonify({'clients': clients})

The problem is that while running the code ang going to main page: http://127.0.0.1:5000, I got an error:

Not found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

In console I can see 404 error:

127.0.0.1 - - [24/May/2022 16:46:30] "GET / HTTP/1.1" 404 - 

I'm using PyCharm IDE, hope that's not the case. I shut down every Python process using CTRL ALT Delete. But it haven't helped me.

CodePudding user response:

your problem is very simple, you must run your app after you define routes. Like this:

from flask import Flask, jsonify
app = Flask(__name__)


clients = [
    {
      'imie': 'Jan',
      'nazwisko': 'Kowalski',
      'produkt': 'Karta podarunkowa Media Expert',
      'wartość': 100,
      'ilość': 2,
    }
]


@app.route('/')
def get_clients():
    return jsonify({'clients': clients})

app.run(port=5000)

Modify your code and it should be fine

  • Related