How can I avoid 'Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again'
Question:
I have Machine learning predictor which predicts number of rooms with price and area. When I click the predict button I get 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). How can I avoid that.
import numpy as np
import sklearn
from sklearn import linear_model
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from flask import Flask, render_template, request
df = pd.read_excel('filtered.xlsx')
x = df[['area','price']]
y =df['number_of_rooms']
x_train, x_test ,y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size = 0.1)
model = LinearRegression()
model.fit(x_train,y_train)
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/predict,', methods=['POST'])
def predict():
price = request.form['price']
area = request.form['area']
rooms = model.predict([[price, area]])[0]
return render_template('predict.html', rooms=rooms)
if __name__ == '__main__':
app.run(debug=True)
My html is like below.
<!DOCTYPE html>
<html>
<head>
<title>House Number of Rooms Predictor</title>
<head>
<body>
<h1>Predict the Number of Rooms of a House</h1>
<form action="/predict" method="post">
<label for="price">Price:</label>
<input type="text" id="price">
name="price"><br>
<label for="area">Area:</label>
<input type="text" id="area">
name="area"><br>
<input type="submit" value="Predict">
</form>
</body>
</html>
Answers:
You have to create a Templates folder for that name must be templates.
I have Machine learning predictor which predicts number of rooms with price and area. When I click the predict button I get 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). How can I avoid that.
import numpy as np
import sklearn
from sklearn import linear_model
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from flask import Flask, render_template, request
df = pd.read_excel('filtered.xlsx')
x = df[['area','price']]
y =df['number_of_rooms']
x_train, x_test ,y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size = 0.1)
model = LinearRegression()
model.fit(x_train,y_train)
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/predict,', methods=['POST'])
def predict():
price = request.form['price']
area = request.form['area']
rooms = model.predict([[price, area]])[0]
return render_template('predict.html', rooms=rooms)
if __name__ == '__main__':
app.run(debug=True)
My html is like below.
<!DOCTYPE html>
<html>
<head>
<title>House Number of Rooms Predictor</title>
<head>
<body>
<h1>Predict the Number of Rooms of a House</h1>
<form action="/predict" method="post">
<label for="price">Price:</label>
<input type="text" id="price">
name="price"><br>
<label for="area">Area:</label>
<input type="text" id="area">
name="area"><br>
<input type="submit" value="Predict">
</form>
</body>
</html>
You have to create a Templates folder for that name must be templates.