I am new to building API. I am building a very Simple API: When executed, The HTML page displaying API will ask to enter name: the Api will just return: "Hello {name}". I am getting 405 Error. Here is my code for App.py and HTML page:
from app import app
from flask import render_template
from flask import request
@app.route('/')
def home():
return "hello no world!"
@app.route('/template',methods=['POST','GET'])
def template():
output = [request.form.values()]
output = output[0]
return render_template('home.html',prediction_text='Hello {}'.format(output))
and my HTML code for home.html:
!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Welcome home</title>
</head>
<body>
<div class="login">
<h1>Enter your name</h1>
<!-- Main Input For Receiving Query-->
<form action="{{ url_for('template')}}"method="post">
<input type="text" name="name" placeholder="Name" required="required" />
<button type="submit" class="btn btn-primary btn-block btn-large">Enter</button>
</form>
<br>
<br>
{{ prediction_text }}
</div>
</body>
</html>
I have looked at several other StackOverflow forums with just this issue. It seems like there is something wrong with "GET" or "POST" method but I can not seem to figure out what? Maybe one of you could see something I did not. I am running this API Inside a Docker so "app = Flask(name)" are stored elsewhere , If that is relevant.
Method Not Allowed - The method is not allowed for the requested URL
Flask - POST - The method is not allowed for the requested URL
https://www.reddit.com/r/flask/comments/a04aew/ask_flask_help_me_to_find_the_error_in_my_code/