0

I have a file.html which contains the following code

{%extends "base.html"%}
    {%block content%}
    <p>Done predicting</p>
    <div>
        <p>Choose files to view results</p>
        <label for="txt_file">txt file</label>
        <input type="file" id="txt_file">
        <label for="ann_file">ann file</label>
        <input type="file" id="ann_file">
        <button type="button" onclick="processFile()">Display</button>
        <script>
            function processFile() {
                var t = document.getElementById("txt_file").value;
                var a = document.getElementById("ann_file").value;
                window.location.href='{{url_for('display',txt=t,ann=a)}}';
            }
        </script>
    </div>
    {%endblock%}

In my routes.py I have the function

@app.route("/display/<txt>/<ann>")
def display(txt,ann):
    return txt + " " + ann

When I pass {{url_for('display',txt='somefile.txt',ann='somefile.ann')}} manually I get the url /display/somefile.txt/somefile.ann, otherwise it gives /display//. Can anyone help? Or is there a better way to do this?

sunil_kr
  • 9
  • 1
  • I believe you are making a typo error with respect to quotes. Do as:- `window.location.href='{{url_for(display,txt='+t+',ann='+a+')}}'` – Maharshi Roy Mar 08 '18 at 13:31
  • Doing `window.location.href='{{url_for(display,txt='+t+',ann='+a+')}}` gives the url as **/display/+t+/+a+** which is obvious because you are passing string directly to the url – sunil_kr Mar 08 '18 at 13:43
  • Put double quotes as & try:- `window.location.href="{{url_for(display,txt=t,ann=a)}}"`. These problems appear frequently and u need to do hit and trial to get things working. – Maharshi Roy Mar 08 '18 at 14:04

0 Answers0