Adventures in Django Deployment: What is a Web Server Anyway?

I recently had some hair-raising adventures in the land of website deployment. I’ve been completely rebuilding my website with a Django backend because I love Python. (This blog will eventually be hosted there, although WordPress does excel at the blog thing, so I might just get crazy and integrate Django AND WordPress. But I digress.) I had everything working all fine and dandy on my local computer and was ready to deploy my almost-identical-but-now-Django-backed placeholder site. I’ve long had Apache serving a few VirtualHosts and handling the SSL certificates on my personal DigitalOcean droplet, so my choice of web server was made for me. At least all that domain config stuff was done, so it would be a cinch to get Django up and running in place of my static site, I thought.

I thought wrong.

It started off so well. I installed python and PostgreSQL on my server and configured my production settings file to match (and to pull in the passwords from a separate ini file on the server and out of the git tracking). I set up a bare repo and some git hooks to make pushing to production easy. (I know I should also set up a separate staging subdomain for testing, but I’ve been in a hurry to get something real up there since I’m starting the ol’ job hunt.) Everything seemed to be ready to push so I turned to the Apache config.

This is where my troubles began. I had been running Django’s testing server locally, but the docs were very clear that this testing server should not be used in production. They did not go into details as to why other than “security and scaling,” but I took their word for it. That’s okay, I thought; I have Apache set up already anyway. The docs also kept talking about this “WSGI” thing, but when I had tried to figure out how to configure that, it had mostly just confused me, and well, it was working on my machine.

Continue reading “Adventures in Django Deployment: What is a Web Server Anyway?”

Tkinter Template

Ball python, Photo credit: Micheal McConville

Tkinter (a shortening of “Tk interface”) is the standard GUI package that comes with python. I’m using it to built my first non-web GUI. I may move to wxPython down the line, but Python 3.5 is not currently supported, Tkinter does what I need it to do, and since the inclusion of ttk (themed Tk), the styling of the widgets look just fine to my eye.

Tkinter documentation and help as far as best practices and design patterns is not particularly thorough or abundant (Tkdocs and effbot have been very helpful references, if not quite sufficient), so I thought I’d put down and share the basic template I wrangled together over a couple of days of learning. Especially because it can be hard to find simple, well-commented skeleton templates for good overall application organization, this is something that would have helped me a lot. I’ve kept all my application logic in other scripts, so this is just the GUI. I’ll probably update this as I learn more; visit the GitHub repository for updates.

Continue reading “Tkinter Template”

Bits and Bytes: ASCII and Unicode

binary code, Photo credit: Turkei89

After running into my recent character encoding conflict with Python, I decided to do a basic explanation of what exactly character encoding means and what the differences are.

As you probably already know, computers at their core ultimately speak a language of just two “letters”: 1‘s and 0‘s, True or False, something or nothing, on or off. That’s why it’s called binary code; there are only two opposing options. Each individual one or zero is known as a bit, a portmanteau derived from “binary digit.”

We humans of course speak languages with many letters; the Cambodian Khmer language has 74 characters! So how do you get a computer to understand all of that? In the early computing days, way back in 1968, this conflict was solved with the development of the ASCII standard (American Standard Code for Information Interchange). ASCII links each letter or character to a unique 8-bit code made up of computer-readable ones and zeroes. These 8-bit chunks of code are known as bytes, a term coined by computer science pioneer Dr. Werner Buchholz. The name fits, doesn’t it? Little bites of code. Anyway, by using 8 bits of binary data, one can get up to 256 different code combinations (that’s 28) ranging from 0 to 255. Now our computer has 256 characters with which to work!


In the ASCII standard, each character is assigned one of these 256 slots, and it can be expressed by its binary code, it’s decimal number (0 – 255), its hexadecimal code, or the human-readable glyph (what you see on your screen or keyboard). For example, an asterisk can be expressed as follows:

Binary: 00101010
Decimal: 042
Hexadecimal: 2A
Glyph: *

Neat! But wait, the first 30 spots are reserved for control/formatting characters, different languages use different alphabets, and what about accents and symbols and special characters? We run into the limitations of 8-bit encoding pretty quickly.

In order to truly be able to express all the characters we might need, we had to move on from the 8-bit model to something that allows for even more combinations of 1’s and 0’s. This expanded alphabet eventually became standardized as the Universal Character Set or Unicode. The original Unicode standard (now called UCS-2) doubled the bit size of each character to 16 bits, and 216 gives us a whopping 65,536 possible combinations! The development of Unicode gets more technical from there, and there are a few different Unicode encodings in use today, but by far the most common are UTC-8 and UTC-16. Where ASCI and UCS-2 both work in fixed-length code units (1 byte or 2 bytes per character, respectively), UTC-8 and UTC-16 are variable-length, allowing for even more combinations. UTC-16 extends UCS-2 by using one 16-bit code unit to represent each UCS-2 character and two 16-bit code units (32 bits total) to represent additional characters. UTC-8 uses one byte for the first 128 characters, just like ASCII, and a variable bit-length of up to 4 bytes for additional characters.

For an even more detailed explanation that’s still easy to understand, check out one or both of the following articles:

Unicode and You

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)