0

I've implemented navigation in a small flask powered website like this and it seems to do the job:

<!-- Navigation (Stays on Top) -->
<div class="w3-top w3-bar w3-black">
<a href="page1" class="w3-bar-item w3-button">Home</a>
<a href="page2" class="w3-bar-item w3-button">Page 2</a>
<a href="Page3" class="w3-bar-item w3-button">Page 3</a>
</div> 

Inside views.py for Page 2 is :

@imprint.route("/page2")
def page2_view():
    return render_template("page2.html")

and homologous for the other pages.

Is there any security risk or other issue with this, why would one instead use the package - https://flask-navigation.readthedocs.io/en/latest/

cardamom
  • 6,873
  • 11
  • 48
  • 102
  • 2
    I don't see how there would be any security risks, but you might have some lag by it rendering the template on each request. – Froggo Dec 02 '22 at 17:08
  • I just read [here](https://hackersandslackers.com/flask-jinja-templates/) _Even though sites seemed to have common elements between pages (such as navigation), the reality was a nightmare of hardcoding these elements by hand on every individual page of a site. Changing a navigation link meant manually making the same change across hundreds of pages._ So a warning to anyone reading this, it may not be a security issue but probably don't do this if you have a site with lots and lots of pages. – cardamom Dec 13 '22 at 10:20
  • It's good to know about this lag in rendering the template on each request. I think in my case, each of the small number of pages has a different form, divs etc so probably have to render with each request anyhow. But if I end up with several pages one day, where they all have similar form, but just different content populated by Flask and Jinja, will bear that in mind. – cardamom Dec 14 '22 at 09:04

1 Answers1

5

I don't see any issues with your approach. As Froggo has pointed out, this might cause a small amount of lag as you are rendering the template for each request, but other than that, it should be fine.

As for the Flask-Navigation package, one of the reasons why people are inclined to use it as it provides a level of convenience for making navigation bars. But looking more closely at the repository, it seems that development has been halted (the last recorded commit was around 7 years ago at the time of writing).

If you do want to use a dedicated navigation package, then Flask-Nav seems to be a good contender, but just as the Flask-Navigation package, this package is also not actively maintained. However, this package is being actively used (according to GitHub), and the community has a workaround to get this package to work with the latest version of Python (3.10.x).

I hope this research helps you.

Undesirable
  • 353
  • 2
  • 12