1

i am new in python flask.i have html file named as header.html .all the html files i have created, are in the /templates folder as discussed in flask documentation. i am having following code in header.html

<li>
  <a href="items" class="dropdown-toggle no-arrow">
        <span class="fa fa-calendar-o"></span><span class="mtext">here i want to display</span>
  </a>
</li> 

my question is , i want to write python flask select query just above my <li> tag and i want to display number of selected items in <span> tag.
i have already applied this below solution

<%
mycursor.execute("SELECT * FROM category")
length=len(mycursor.fetchall())
%>

however its not working.i am using mysql database.any help will be appreciated.
  • Send the data from the backend the the frontend. don't execute sql code with jinja2 – Patch Jul 16 '20 at 07:07
  • i appreciate your help.one more thing is,we need to send data from backend everytime?. is it possible sometines to write pyton code in html file? –  Jul 16 '20 at 07:11
  • You can write simple if-else, for loops but I don't see why you would need to handle all the logic in the template itself. – Phani Rithvij Jul 16 '20 at 07:16
  • i want to display some default data in header.html file which is come from mysql database. header.html is same file for all project files.i am using blueprint in flask.i have created different blueprints for different moduls in my project.so i have to send this default data from all my blueprints ? @PhaniRithvij –  Jul 16 '20 at 07:25
  • Have a look at this https://stackoverflow.com/q/9679038/8608146 – Phani Rithvij Jul 16 '20 at 07:26
  • i have done same thing in my project and thats not an issue. what i am asking is , each blueprint rendering separate html file which is including header.html. data sended in html file from blueprints.there are many bluprints in my project .so from which blueprint i have to send data? @PhaniRithvij –  Jul 16 '20 at 11:10

0 Answers0