starting a new Django site with a YAML file

Posted on Dec 23, 2016 at 04:36AM

Using a simple construct I've been tinkering with, I have put up a website for the new consultancy that's got a fair bit of complexity to it. I registered the domain on November 25th and as of today, about a month later, it's showing up on the front page when I google "framework labs" and I'm on page 3 for "framework labs continuous integration." For being about 4 weeks old, I'll take it.

The main things I wanted to be able to do are:

  • single-command deploy
  • make editing copy, images, etc. really easy
  • bake-in some SEO goodness so I'm as google-able as a fledgling consultancy can be

I quickly knocked out the single-command deploy with Corrigible and a new Digital Ocean droplet. Yay automated deployment!

For the Freshnoms MVP (more on that later), I had kicked off the project putting pertinent site-related things in a YAML file. I built a basic configuration class that reads the YAML once per process and makes it available with a call to a lookup() method. I've found that it's been pretty easy to build around that idea and it's made a lot of things a bit nicer.

I'm liking the structured, but free-formy feel of combining a general purpose config class with a YAML that I can grow, change, etc. without having to dig around a bunch of python or html. I can put all the website images in the YAML file along with the license information so I don't misplace it. I can define a list of templates that will make up the front page and, to reorder those templates, I can just change the position of the templates in the config and not mess with the template.


It's also admittedly an experiment and I may follow up this post at some point down the road with a post called "Why you should never build a web site around a YAML file."

But, since it's been smooth sailing so far, I decided to expand on the idea for the consultancy website.

So, instead of simply reading from a config file, I decided to do what Ansible has done and do a two pass read with an in between run through the django template engine. Note that this isn't actually what Ansible has done, but rather something that's similar to what I've previously done with Corrigible, which is more or less inspired by what the Ansible developers have done


I've complicated things a bit by having a way to do config lookups on unprocessed yaml, processed yaml, and late-rendering processed yaml that affords me the option of adding some new variables to be made available to the template rendering engine, but the basic idea is:

  1. Read the yaml into a dict, N, using just the YAML interpreter
  2. Read the yaml into a string, S
  3. Run the string, S, through the Django template engine and give it the dict N as the variable dict to be used in the Jinja-style template tags. This produces a processed string version of S, which I'll call T
  4. I think read T into a dict, M
  5. I can then use a simple lookup method to extract data from M


So, with this neato whizbang contraption, I was able to add and remove pages, do lots of iterations on the copy, and make styling the site worlds easier. I used it to spin up a small army of landing pages and I've even got some reusable form components that I can string together to create custom contact forms.

Beyond that, it feels like a very proper separation of concerns, which I like, although, because I'm definitely exploring new territory, I've had to backtrack and rethink a thing or two along the way. I've got some high hopes though and I'm definitely pleased with the amount of leverage it's provided me for the effort that's gone into it.

I'll expand on the SEO-related tactics in a later post.