javascript - flask: how to get a POST endpoint to redirect correctly -


have complicated endpoint in flask deployed server:

@app.route('/whatever', methods=['get', 'post']) def somefunct:     if request.method = 'post':         << stuff >>      << other stuff >>     return render_template('sometemplate.html', **<<variable dict>>) 

that pushes 1 template.

sometemplate.html kind of tricky, contains table pulls data variable dictionary , provides dropdown allows user interact it:

{% item in << variable in dict >> %}  ...  <td>     <form name="category-form" id="category-form-{{ item }}" action="/whatever">         <select name="{{ item }}" id="{{ item }}">             <option value="1">option 1</option>             <option value="2">option 2</option>             <option value="3">option 3</option>         </select>     </form> </td> 

and have javascript trigger right post action (jquery loaded):

$(document).ready(function() {     {% item in << variable in dict >> %}      var form{{ item }} = $('category-form-{{ item }}');      form{{ item }}.find('#{{ item }}').change(function(){         $.ajax({             type: "post",             url: form{{ item }}.attr('action'),             data: form{{ item }}.serialize(),             success: function(response){                 console.log("calling {{item}}")             }         });     });      {% endfor %} }); 

all of works correctly in dev environment, when push our server, i'm getting 500 errors in javascript console. suspicion there's funky going on request object -- i've been able narrow down i'm getting error didn't before when try parse through it.

as part of troubleshooting, since i'm running apache server , don't have easy access output, thinking might wise redo endpoint follows:

@app.route('/whatever', methods=['get', 'post'])     if request.method = 'post':         << stuff >>         variable = << variable test >>         return render_template('test.html', **{"variable"=variable})      << other stuff >>     return render_template('sometemplate.html', **<<variable dict>>) 

and set test.html be:

{{ variable }} 

(with correct blocks around it, etc.)

however, when try implement this, after selecting dropdown, doesn't redirect test.html, though can tell javascript console , creative use of return statement in code it's tracing through correct part of endpoint.

my guess way javascript set up, want able redirect test.html in order see request object looks , why it's malformed.

how do redirect in context?

of course if have ideas why code wouldn't working on server when it's working on localhost, i'd ears :)


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -