Q:

html form - get rid of question mark and equation

Here's my code:
{% if request.path == '/employees' %}
    <form action="{{ url_for('employees_name', employee_id=x) }}" />
    EmployeeId: <input type="text" name=x><br>
    <input type="submit" value="Submit">
    </form>
{% endif %}

E.g. when I input "1" as an output I get:
http://127.0.0.1:5002/employees/?x=1

but I need this:
http://127.0.0.1:5002/employees/1

Here's my Python code:
app = Flask(__name__)
api = Api(app)

class Employees_Name(Resource):
    def get(self, employee_id):
        conn = db_connect.connect()
        query = conn.execute("select * from employees where EmployeeId =%d "  %int(employee_id))
        result = {'data': [dict(zip(tuple (query.keys()) ,i)) for i in query.cursor]}
        return Response(render_template('test.html', result=result, mimetype='text/html')) 

api.add_resource(Employees, '/employees')

Is there a way to do it? Thanks

A:

When using 'GET' to handle form, the form data will be formatted as a query string appended after URL. The normal way is to use a POST endpoint to handle form and validate form data, then redirect to a GET endpoint like yours.
So, the code may like this:
from flask import request, url_for, redirect
...

class Employees(Resource):
    def post(self):
        employee_id = request.form.get('employee_id')
        # validate...
        return redirect(url_for('employee', employee_id=employhee_id)) 

class Employee(Resource):
    def get(self, employee_id):
        conn = db_connect.connect()
        ... 

api.add_resource(Employees, '/employees')
api.add_resource(Employee, '/employees/<int:employee_id>')  # this rule is waht you want

In the template:
<form action="{{ url_for('employees') }}">
    EmployeeId: <input type="text" name="employee_id"><br>
    <input type="submit" value="Submit">
</form>

