I'm writing a program in flask. In one of the pages (/search), the user will have a field to enter a string and click a search button. The result page that follows works all right, which consists of an html page with several images on it.
Now i want to add a button next to each image that, once clicked, will add an item to my mongoDB database.
So, 2 problems:
1) The buttons i managed to create so far will demand a "return redirect(page)". I don't want that. The user must be allowed to click several buttons in sequence, instead of having to perform a new search.
2) i built my own mechanism for rendering the result.html page. According to the search results, my code opens result.html and writes (appends) the urls on it.
@app.route('/add', methods = ['POST'])
def add():
print "hi"
return None ##Python won't accept 'return None' here =(
[...]
w=open("result.html", "a")
[...]
for k in cursor:
try:
w.write(k['url'] + "'> <form action='/add' method='post'> \
<input type='submit' value='Add'></input></form>")
How can i make the button tell the /add view function know the url for each image? I suppose there is something i should replace in this last block of code.