0

So basically I have a page the renders rows from a database

{% for q in rows %}
<tr>
<td>Column 1</td>
<td>
    <a href="#modalUpload" data-toggle="modal" data-question-id="{{q.id}}">Upload</a>
</td>
</tr>
{% endfor %}

The second column is a link to a modal page

<div class="modal fade" id="modalUpload" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
  aria-hidden="true">
<div class="modal-content">
{{ dropzone.create(url_for('uploadImages', qid=??????)) }}
{{ dropzone.config(redirect_url=url_for('examQuestions', examid=examid)) }}
</div>

my javascript code

$('#modalUpload').on('show.bs.modal', function(e) {
    var qid = $(e.relatedTarget).data('question-id');
});

What I need is to send the qid variable to the url_for contents... I know I can't do it because the page is already rendered before this js code is executed.. my question is, can I render the modal after this page is executed? I tried with ajax and flask server-side sending new data to my page, and then replacing the html contents, but I can't get it to work.. code are being sent as text not code

Edit: I know with dynamic contents I can load html code, but how is this supposed to work with my code? Here is my code that instead of returning a jinja code it returns a text

$(document).ready( function() {
        $('#modalUpload').click(function() {


            $.ajax("{{ url_for('gnp', qid=qid) }}").done(function (reply) {

              $('#modalcontent').html(reply);
           });



        });
    }); 

Reply is

{{ dropzone.create(url_for('uploadImages', qid=10)) }}
{{ dropzone.config(redirect_url=url_for('examQuestions', examid=examid)) }}

which is shown in my modal as text instead of being run by jinja2

Hadi
  • 705
  • 8
  • 23
  • You pretty much have the answer to your question. It's yes, you have to use ajax to request the contents of the modal. If you are having trouble getting that to work, SO has lots of questions about loading dynamic modal content. If those don't help, post your own question with the issue you are having. – noslenkwah Apr 14 '20 at 15:25
  • @noslenkwah the code returned by flask is being shown as it is without being rendered by jinja2... I edited my post with the code – Hadi Apr 14 '20 at 16:07
  • This is a different question than originally asked. It should be formulated into it's own question. But before you do that I would do some searching on how to dynamically load modal content. It's unlikely the problem you are facing isn't already answered on this site. – noslenkwah Apr 14 '20 at 16:42

0 Answers0