How to access (in Google App Engine) the input that is created dynamically:
<form action="/add" method="post">
<input type="text" name="line[]">
<input type="text" name="line[]">
<input type=submit">
I tried to access it via:
for i in self.request.get('line[]'):
self.response.out.write(i)
#this only gives first value
or
self.response.out.write(self.request.get('line[]')[1])
#this gives index out of range.
Ok, i got it, i supposed to use self.request.get_all('line[]')
Related
I've a HTML form for editing existing data.
Let's say today is 10/06/2022 18:05 and i want to edit my course date time in my web app.
My course date on the data base is 21/08/2023 10:00. I want to change it to 22/08/2023 10:00. When I open my from on the web app all the inputs came with the existing data already selected. But date time picker comes as 10/06/2022 18:05. I've set the value as the date attribute of course object but it's not working. This works for the rest of the inputs but not for the datetime input.
I basically need the html date time picker comes with autoselected with the existing saved data <course.date> .
I'm writing this web app on python flask and using a postgresql for database. The other inputs comes with selected values but not datetime input.
Anyone has any ideas how to approach this one?
<form action="/courses/{{course.id}}" method="post">
<label for="course">Course Title</label>
<input type="text" name="title" value="{{course.title}}">
<label for="date">Date</label>
<input type="datetime-local" name="date" value="{{course.date}}">
<label for="capacity">Capacity</label>
<input type="number" name="capacity" value="{{course.capacity}}">
<label for="active">Active</label>
<select name="active">
<option value="True">Active</option>
<option value="False" {% if course.active == False %} selected {%endif%}>Deactive</option>
</select>
<input type='submit' value="Update Course">
</form>
If I am understanding the issue right:
course_date in the database is: 21/08/2023 10:00
course_date in the app remains as the local-current time: 10/06/2022 18:05 (example)
GET request properly loads data from the database into the other fields except course-date
you've tried making a POST request to update course_date, but the field doesn't change
My suggestion to debug this is to look at the responses to your GET request. What do they come out as?
Inside your GET request's response,
if the course-date is 21/08/2023 10:00, that means your problem is in your javascript or the code that plugs in your field value inside the HTML. Your frontend field is simply ignoring the response from flask or the data is not being mapped/handled right
if the course-date is 10/06/2022 18:05 or is null. That means your flask backend is broken, double-check the flow of your data from the SQL select -> storing the data in a python variable -> sending the data out
Also remember to Hard-Reload.
Based on our exchange in comments, it looks like the issue is with the date format being passed in your template.
Changing:
<label for="date">Date</label>
<input type="datetime-local" name="date" value="{{course.date}}">
To:
<label for="date">Date</label>
<input type="datetime-local" name="date" value="{{course.date.isoformat()}}">
Should correct the problem for you.
I have some html code that contains a form. When submitted it sends a post request to a server. The form has various inputs, each with a name and a value, however there are some inputs with the same name.
Here is an example of what I mean:
<form action="http://example.com" method="post">
<input name="name" value="val">
<input name="name" value="val">
<input type="submit">
</form>
First, I am confused as to how there can be two values of the same name. Please note that I have tried removing one of the instances of <input name="name" value="val"> however this returns an error so it seems that both instances are needed.
Second, I am trying to convert this to a python request using the request library.
I have the following request:
requests.get(url = URL, params = PARAMS).json()
Where PARAMS is a dictionary of the various inputs. For example:
PARAMS = {'name':"val"}
However, being a dictionary, I can't have multiple instances of the same value. How do I make this work? Thanks
If there are duplicated names then the values will be in an array with the name. The demo below sends to a live test server and the response is directed to an <iframe>
<form action="https://httpbin.org/post" method="post" target="response">
<input name="name" value="val">
<input name="name" value="val">
<input type="submit">
</form>
<iframe name='response'></iframe>
What you are looking for is to use input arrays. With them, you can have many inputs sharing the same name, and in the server side, the data will be treated as an array. So the HTML would be:
<form action="http://example.com" method="post">
<input name="name[]" value="val1">
<input name="name[]" value="val2">
<input type="submit">
</form>
I'm not sure whether you can do this or not, so I just wanted to ask.
I have variables on my python file and I want to send them to another python file to use. So for instance
username= "John250"
passw = "pass"
Now I believe I need to change the value of each input type for this to work, but I'm scratching my head over what to change it to.
print ("""
<form name="myform" class="myform" action="index1.py" method ="post">
<input type="hidden" name="Username" value = "Hi">
<input type="hidden" name="password" value = "Hi">
</form>
""")
Any ideas??
(I'm using js to submit the form automatically hence why there is no submit button)
I use google app engine and python. I want to retrieve the id of an input and not the value. If I use self.request.get("thename") I get the value of the input.
Here is the html
<form method="post">
<input value=" " type="submit" name="thename" id="thenumberIneed"/>
</form>
I cannot put my data on the value tag because I have an image as a background on the input and if I enter there anything, the data shows infront of the image. So, I keep value empty.
If you don't want the value to show, change it to:
<input type="hidden" ... />
But I suspect there are other problems you should be solving, like why does your image get in the way of showing values in the page, and what kind of data you want to retrieve.
You shouldn't be using the id for this type of logic.
You would have better luck using a seperate hidden input field, for example.
<input type='hidden' name='myval' value='thenumberyouneed' />
And then you can just do your search for myval and get your answer.
Hello I am making a form in HTML and python and I am having a problem with processing the arguments
the problem comes in this section
<form method="POST">
<input type="checkbox" name="brands" value="1" />
<input type="checkbox" name="brands" value="2" />
</form>
and in the python I am using a self.request.form object to retrieve the arguments
the problem is if I do something like
for b in brands:
print b
it will just print out 1 even if both of them are in the self.request.form object
USING Werkzeug Framework
ANSWERED:
I found you can retrieve a list of the same named inputs using this syntax
self.request.form.getlist('brands')
I found you can retrieve a list of the same named inputs using this syntax
self.request.form.getlist('brands')