Sure, here's a code sample demonstrating how to properly retrieve parameters from a query in an Odoo 16 controller:
python Copy code from odoo import http
class MyController (http.Controller):
@http.route( '/route/' , type = 'http' , auth= 'public' , website= True )
def my_route ( self, **kwargs ):
from_param = kwargs.get( 'from' )
to_param = kwargs.get( 'to' )
# Your processing logic here
return "From: {}, To: {}" . format (from_param, to_param)
In the code above, we define a controller class MyController with a route /route/ . When a request is made to this route with query parameters like /route/?from=...&to=... , the my_route method will be executed. The **kwargs parameter allows us to capture all the query parameters passed to the route.
We then use the kwargs.get() method to retrieve the specific query parameters we are interested in, namely from and to . The get() method returns None if the parameter is not present, or the parameter's value if it exists.
Finally, you can perform your processing logic with the from_param and to_param variables as needed. In the example provided, we simply return a formatted string displaying the values of from_param and to_param . You can replace this with your actual processing and response logic.
did you already found what you were looking for?