Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Richard Hriech
Richard Hriech
12,001 Points

What should I use? Jinja's {% extend ... %} or an AJAX request?

So if I'm building a Flask web app, where the site has a static navbar, sidebar and a main page content that changes when the user clicks on a link, which is the way to go?

  1. Making a "layout.html" with a {% block content %} and the subpages of the site extend this layout and change the content,


  1. Not using Jinja's templating, but requesting a html snippet from the server with an AJAX get request, and only changing the <div> of the main content while the navbar and other static stuff remain untouched and don't get refreshed.

Is the AJAX way faster or more data usage friendly? Or the browsers are clever enough to cache the navbar, css, and scripts and they don't reload them every time I go to a subpage?

1 Answer

Jeff Muday
Jeff Muday
Treehouse Moderator 28,716 Points

Personally, I'd go with the Jinja approach. Since we are already doing the majority of the work on the server-side, why not extend a base-layout. Of course, I am weak at Javascript ;-)


  1. If you want to change the layout, you only have to do it in 1 file (admittedly, well-crafted AJAX is nice and modular too!)
  2. If you have a client that doesn't support javascript, Jinja will produce the static pages.

That being said... there is a new trend of doing "serverless" pages-- but that discussion is better left for another day!