I have a dataset of Players and the number of goals they have scored, this dataset is stored in a dataframe. I want to display or print the stats and player details that I have searched for on the search bar, but I am always getting a bad request error
This is the dataset Dataset Screenshot
this is how the Webpage looks like Webpage screenshot
MainProject Python file
import pandas as pd
from pandas import DataFrame
from fuzzywuzzy import process
scorers=pd.read_csv('tests.csv')
def main(searchplayer):
scorers=pd.read_csv('tests.csv')
player=list(scorers['Player'])
goals=list(scorers['Goals'])
team=list(scorers['Team'])
df_data={'player': player,
'goals': goals,
'team': team}
df_main=pd.DataFrame(df_data, columns=['player', 'goals', 'team'])
def getSearchedProducts(searchplayer, choices, limit=30):
res=process.extract(searchplayer, choices, limit=limit)
return res
searchplayer=str(searchplayer)
result=getSearchedProducts(searchplayer, player)
player_result_list = [res[0] for res in result if res[1]>=70]
player_result_df = df_main[df_main['Product'].isin(product_result_list)]
player_result_df.index+=1
list_player_res=[(tabulate(player_result_df, headers='keys', tablefmt='psql'))]
return list_player_res
Flask File
import os
from flask import Flask, flash, request, render_template,
redirect, url_for, send_from_directory
from werkzeug.utils import secure_filename
from MainProject import main
from flask_cors import CORS
searchplayer=""
app=Flask(__name__)
app.config['CACHE_TYPE']='null'
CORS(app)
@app.route('/', methods=['GET', 'POST'])
def homepage():
searchplayer=request.form['prod']
list_player_res = main(searchplayer)
return render_template('home.html', list_player_res=list_player_res)
if __name__ == "__main__":
app.run()
A code snippet of my Html file
<form class="form-inline" method="POST">
<input class="form-control mr-sm-2" name="prod" type="search" placeholder="Search for Players" aria-label="Search">
<button class="btn btn-light my-sm-0" type="Submit">Search</button>
</form>
This is what I tried:
@app.route('/')
def homepage():
return render_template('home.html')
@app.route('/searchpg', methods=['GET', 'POST'])
def searchpg():
global searchplayer
if request.method == 'POST':
searchplayer = request.form.get['prod']
list_res, list_prod_res = main(searchplayer)
print(list_player_res)
return render_template('home.html', list_player_res=list_player_res)
HTML This is what I did:
<form class="form-inline" method="POST">
<input class="form-control mr-sm-2" name="prod"
type="search" placeholder="Search for Players" aria-label="Search">
<button class="btn btn-light my-sm-0"
type="Submit">Search</button>
</form>
</div>
</nav>
<br>
{% for result in list_player_res %}
{{result}}
{% endfor %}
</br>
How do I search for players in that searchbar and the results get displayed on the same screen?