I am currently trying to use Brython for the website I am making, but I cannot get the data from the user for my program.
I set up a box for the user to type in an ID...
<form name="levelid" action="" method="get">
<input type="text" name="id" id="idresposne">
<input type="submit" value="Search">
</form>
...then the current method I use is to make it append the URL using the GET method. This makes the URL looks like this.
https://mywebsiteurl.com/website.html?id=12345678
I know I can extract the id
parameter using window.location.search
and then URLSearchParams
in JavaScript, with a code like this. This allows me to use the variable id_i_needed
which now holds the argument, 12345678
for the above example URL.
var levelqm = window.location.search;
levelqm = new URLSearchParams(levelqm);
var levelid = levelqm.get("id");
However, I cannot seem to find anything given by the Brython documentation that it can obtain URL information, nor find a way to make Brython communicate with JavaScript.
Is there something that allows me to do a similar thing as the JS code? If this is not possible with Brython, is there a library that I can look for to achieve the same thing?
I wrote the code that processes that ID in Python, which is why I am fiddling with Brython in the first place.
(Thanks to Hernán Alarcón for directing me to this.)
Because I used the GET request, which will append the parameters to the URL, Brython has an attribute query
that searches for URL parameters.
Using the expression document.query['id']
will give 12345678
for the example URL. This yields the same results as the JavaScript code posted in the question.
Apparently I missed this page of documentation at Brython.