-1

This might sound noob but this is causing me a lot of delay in my work and I have no idea why. I am using Flask to pass some variables to my html, but apparently they don't seem to be able to resolve the values.

Examples:

The url_for here doesn't work I don't really know why:

<link rel ="stylesheet" href = "{{url_for('static', filename='css/bootstrap.min.css')}}">

The graph_data can't be resolved here too. Instead it shows this output graphing.html!

  <div class="container" align="left">
        <embed type="image/svg+xml" src={{graph_data|safe}} style='max-width:1000px'></embed>
  </div>

Even though I already passed the values through Flask

    graph = pygal.Line()
    graph.title = '% Change Coolness of programming languages over time.'
    graph.x_labels = ['2011','2012','2013','2014','2015','2016']
    graph.add('Python',  [15, 31, 89, 200, 356, 900])
    graph_data = graph.render_data_uri()
    return render_template("graphing.html", graph_data = graph_data) #Here! 

So what's the problem? My file fask-demo.py is located as shown

Structure of the static folder

structure of my static file

The code of my graph.html file is

{% extends "header.html" %}
{% block body %}
<body class="body">
      <div class="container" align="left">
            <embed type="image/svg+xml" src={{graph_data|safe}} style='max-width:1000px'></embed>
      </div>
</body>
{% endblock %}

I am assuming that the header file is fine because it is already working with other templates. But I will show it if needed.

Ahmed Al-haddad
  • 805
  • 2
  • 16
  • 41

1 Answers1

2

Ok. This is embarrassing but whatever man. There are two problems, the IDE (PyCharm Professional Edition) and the code.

  • Firstly, the IDE kept on saying that it couldn't resolve the code, while it actually code. This gave me the impression that it was not working properly even though it did. So I guess the PyCharm guys need to fix this.

  • Secondly, the graphing.html was not the correct html file that was supposed to be passed. But since the IDE kept on telling me that it couldn't resolve the {{ var }} and { url_for}, then I assumed that it was because of these two that the web app didn't work, and I forgot to verify the real problem.

Ahmed Al-haddad
  • 805
  • 2
  • 16
  • 41