python3 flask: how to display the json result in html





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Now I want to send the json data to html, I just display the dictionary data(json), How to display the value of dictionary in the html.
The python code is:



@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
img_file = request.files['img_file']
if img_file and allowed_file(img_file.filename):
filename = secure_filename(img_file.filename)
img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
raw_img_url = './static/asset/uploads/' + filename
result_img_url = './static/asset/output/Line/' + filename

ratio = check_banner(filename)
result_dict = {'result': ratio}

return render_template("upload.html", result_img_url=result_img_url, result=json.dumps(result_dict))
else:
return ''' ok</p> '''
else:
return redirect(url_for('upload'))


The html code:



{% extends "base.html" %}
{% block content %}

<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" id="img_file" name="img_file" class="col-sm-4">
<input type="submit" value="check" class="btn">
</form>

<p>
{% if result_img_url %}
<img src="{{ result_img_url }}" width='400' height='350'>
{% endif %}
</p>

<ul>

<li>{{result}}</li>

</ul>


{% endblock %}


But the result html is, but I just want to show the value of result :



result html










share|improve this question





























    0















    Now I want to send the json data to html, I just display the dictionary data(json), How to display the value of dictionary in the html.
    The python code is:



    @app.route('/upload', methods=['GET', 'POST'])
    def upload():
    if request.method == 'POST':
    img_file = request.files['img_file']
    if img_file and allowed_file(img_file.filename):
    filename = secure_filename(img_file.filename)
    img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    raw_img_url = './static/asset/uploads/' + filename
    result_img_url = './static/asset/output/Line/' + filename

    ratio = check_banner(filename)
    result_dict = {'result': ratio}

    return render_template("upload.html", result_img_url=result_img_url, result=json.dumps(result_dict))
    else:
    return ''' ok</p> '''
    else:
    return redirect(url_for('upload'))


    The html code:



    {% extends "base.html" %}
    {% block content %}

    <form method="post" action="/upload" enctype="multipart/form-data">
    <input type="file" id="img_file" name="img_file" class="col-sm-4">
    <input type="submit" value="check" class="btn">
    </form>

    <p>
    {% if result_img_url %}
    <img src="{{ result_img_url }}" width='400' height='350'>
    {% endif %}
    </p>

    <ul>

    <li>{{result}}</li>

    </ul>


    {% endblock %}


    But the result html is, but I just want to show the value of result :



    result html










    share|improve this question

























      0












      0








      0








      Now I want to send the json data to html, I just display the dictionary data(json), How to display the value of dictionary in the html.
      The python code is:



      @app.route('/upload', methods=['GET', 'POST'])
      def upload():
      if request.method == 'POST':
      img_file = request.files['img_file']
      if img_file and allowed_file(img_file.filename):
      filename = secure_filename(img_file.filename)
      img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      raw_img_url = './static/asset/uploads/' + filename
      result_img_url = './static/asset/output/Line/' + filename

      ratio = check_banner(filename)
      result_dict = {'result': ratio}

      return render_template("upload.html", result_img_url=result_img_url, result=json.dumps(result_dict))
      else:
      return ''' ok</p> '''
      else:
      return redirect(url_for('upload'))


      The html code:



      {% extends "base.html" %}
      {% block content %}

      <form method="post" action="/upload" enctype="multipart/form-data">
      <input type="file" id="img_file" name="img_file" class="col-sm-4">
      <input type="submit" value="check" class="btn">
      </form>

      <p>
      {% if result_img_url %}
      <img src="{{ result_img_url }}" width='400' height='350'>
      {% endif %}
      </p>

      <ul>

      <li>{{result}}</li>

      </ul>


      {% endblock %}


      But the result html is, but I just want to show the value of result :



      result html










      share|improve this question














      Now I want to send the json data to html, I just display the dictionary data(json), How to display the value of dictionary in the html.
      The python code is:



      @app.route('/upload', methods=['GET', 'POST'])
      def upload():
      if request.method == 'POST':
      img_file = request.files['img_file']
      if img_file and allowed_file(img_file.filename):
      filename = secure_filename(img_file.filename)
      img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      raw_img_url = './static/asset/uploads/' + filename
      result_img_url = './static/asset/output/Line/' + filename

      ratio = check_banner(filename)
      result_dict = {'result': ratio}

      return render_template("upload.html", result_img_url=result_img_url, result=json.dumps(result_dict))
      else:
      return ''' ok</p> '''
      else:
      return redirect(url_for('upload'))


      The html code:



      {% extends "base.html" %}
      {% block content %}

      <form method="post" action="/upload" enctype="multipart/form-data">
      <input type="file" id="img_file" name="img_file" class="col-sm-4">
      <input type="submit" value="check" class="btn">
      </form>

      <p>
      {% if result_img_url %}
      <img src="{{ result_img_url }}" width='400' height='350'>
      {% endif %}
      </p>

      <ul>

      <li>{{result}}</li>

      </ul>


      {% endblock %}


      But the result html is, but I just want to show the value of result :



      result html







      python-3.x web flask






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 1:48









      tktktk0711tktktk0711

      611834




      611834
























          1 Answer
          1






          active

          oldest

          votes


















          1














          If you want to pass only one parameter in result, you may change result_dict = {'result': ratio} to result = ratio.



          It will show only the result in the page:



          show only value






          share|improve this answer
























          • OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

            – tktktk0711
            Nov 23 '18 at 4:27













          • but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

            – tktktk0711
            Nov 23 '18 at 4:28











          • @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

            – arsho
            Nov 23 '18 at 6:16














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439774%2fpython3-flask-how-to-display-the-json-result-in-html%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          If you want to pass only one parameter in result, you may change result_dict = {'result': ratio} to result = ratio.



          It will show only the result in the page:



          show only value






          share|improve this answer
























          • OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

            – tktktk0711
            Nov 23 '18 at 4:27













          • but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

            – tktktk0711
            Nov 23 '18 at 4:28











          • @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

            – arsho
            Nov 23 '18 at 6:16


















          1














          If you want to pass only one parameter in result, you may change result_dict = {'result': ratio} to result = ratio.



          It will show only the result in the page:



          show only value






          share|improve this answer
























          • OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

            – tktktk0711
            Nov 23 '18 at 4:27













          • but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

            – tktktk0711
            Nov 23 '18 at 4:28











          • @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

            – arsho
            Nov 23 '18 at 6:16
















          1












          1








          1







          If you want to pass only one parameter in result, you may change result_dict = {'result': ratio} to result = ratio.



          It will show only the result in the page:



          show only value






          share|improve this answer













          If you want to pass only one parameter in result, you may change result_dict = {'result': ratio} to result = ratio.



          It will show only the result in the page:



          show only value







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 3:48









          arshoarsho

          4,14411838




          4,14411838













          • OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

            – tktktk0711
            Nov 23 '18 at 4:27













          • but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

            – tktktk0711
            Nov 23 '18 at 4:28











          • @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

            – arsho
            Nov 23 '18 at 6:16





















          • OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

            – tktktk0711
            Nov 23 '18 at 4:27













          • but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

            – tktktk0711
            Nov 23 '18 at 4:28











          • @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

            – arsho
            Nov 23 '18 at 6:16



















          OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

          – tktktk0711
          Nov 23 '18 at 4:27







          OK thanks!, after I do this, I want to do:{% if result <= 0.2 and (size is 1) %} <th> Pass </th> <th> {{ type(result) }} </th> {% elif result = 0.24 and (size is 1) %} <th> Need Check </th> {% (elif result > 0.24 and size is 1) or (size is 0) %} <th> no pass </th> </p>

          – tktktk0711
          Nov 23 '18 at 4:27















          but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

          – tktktk0711
          Nov 23 '18 at 4:28





          but there is error: jinja2.exceptions.TemplateSyntaxError: expected token 'name', got 'integer'

          – tktktk0711
          Nov 23 '18 at 4:28













          @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

          – arsho
          Nov 23 '18 at 6:16







          @tktktk0711, if this answer solves the queries in scope of the question please accept it. For further queries, add a separate question with details of the template and error traceback. Asking questions in comments and answering them in comments are not advised in Stackoverflow. :)

          – arsho
          Nov 23 '18 at 6:16






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439774%2fpython3-flask-how-to-display-the-json-result-in-html%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?