I’m not going to pull any punches: right now, our app looks pretty tragic. If only we could hire twenty designers and sixteen HTML genies, our live would be much better: as it stands, though, we have about sixteen minutes to make our app presentable.
We’re going to rely on the exact same shortcuts we rely on every time we want to get something done: libraries and frameworks!
“Oh no!” you say. “Not more libraries and frameworks!”
Yes, more libraries and frameworks! In the same way that Flask is a shortcut to building the backend of our web site, there are libraries that help design the frontend of your site, too.
Introducing: HTML/CSS/JS Frameworks!
Frontend frameworks range from being simple ways of styling a page (e.g. Pure) or fully-featured, everything-under-the-sun factories (e.g. Bootstrap).
We’re going to work with Bootstrap: http://getbootstrap.com/, because once you work with it you’ll realize like 70% of the hip sites on the internet are built with it.
This code going to go into layout.html, since it is, of course, a layout, but I’m going to make two important changes before we save t:
First: On top of stealing it: we don’t want to host a bunch of files: all that .js and .css would just clutter up our directories, right? Luckily, the files are hosted on a CDN, which means someone else can host them and we just get to use them! I’m changing the JavaScript and CSS links in the template to use BootstrapCDN instead of local files.
Second: Where the content goes (they have a header and some text), I’m changing the code to {% block content %}{% endblock %}. As we learned in our introduction to layouts, this will let us frame our content with the layout.
layout.html
And that’s it!
You can now use Bootstrap’s powerful styling tool - take a peek at their CSS introduction. You add special classes to things and wham! Fancy styles.