First, my code.
HTML
<form action= "/" onSubmit= "return validate(this);" method= "post">
<!--irrelevant from this point-->
Javascript, later in the file
<script language= "JavaScript">
function validate(form){
if(form.text_box.value == ""){
alert("Please enter something");
return false;
}
search_string = form.text_box.value;
var encoded = encodeURIComponent(search_string).replace(/%20/g,'+');
form.action = "/search_results/" + encoded;
return true;
}
</script>
Lastly, the python/flask backend.
@maverick.route('/search_results/<search>', methods= ['GET', 'POST'])
def generateSearchResults(search = None):
search_string = urllib.unquote_plus(search)
To explain, I am trying to quote a string before I put it in my url, because that string will contain slashes. However, when I do the search, the page doesn't load and I see this is the url bar.
http://localhost:7666/search_results/%2Fthis%2Fis%2Fmy%2Fsearch
Does anyone see any problems with my setup?