4

My app takes some parameters from a form, uses it as input for another script, and then returns the output. How can I create a refresh button to redirect the user on the initial page without output? I tried this code in the template:

<form action= {{url_for('index')}} method='POST'> 
    <input type='submit' value="REFRESH">
</form>

But this gave me an error that the "View function did not return a response". I also tried:

<form action= {{redirect(url_for('index'))}} method='POST'>
    <input type='submit' value="REFRESH">
</form>

But this gave me the error "'redirect' is undefined" even though my view imported both redirect and url_for.

1

2 Answers 2

7

You don't need to submit a form to clear the values in it. You can use a reset button.

<input type="reset" value="REFRESH">

This will restore the values -- or lack thereof -- from when the page loaded.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for Your reply. But the suggested solutions will clear only the submit form . But my python script also prints out onto web page some python objects such as lists, dictionary and etc. So it would be great to have button to return to the initial web page (index.html) with clear submit form and also without any python objects.
You don't need a POST for that. You don't even need a form. A link will be sufficient. <a href="{{ url_for('index') }}">REFRESH</a>. That said, your view needs to return a response. Search this site for your error and you'll find other who have asked the question.
Thanks a lot. Your solution is exactly what i need, i only slightly modified it. Now there are no errors. <a href="{{ url_for('index') }}"><button>REFRESH</button></a>
<a href="{{ url_for('index') }}"><button>REFRESH</button></a> is better
4

Use <a href="{{ url_for('index') }}"><button>REFRESH</button></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.