No doubt if you’re reading this you’re more computer literate than our friend Senator Stevens or John McCain. But what do you really know about the glorious series of tubes that is the internet? For the past couple of months I’ve been on a self-education binge, so naturally I was troubled when I realized that I had absolutely no idea how a website works or how people build them. I must confess though, my interest in learning about web development is not purely academic. When I have my brilliant idea for a startup I want to be ready for it, and I don’t want to handcuff myself to being just another non-tech guy with an idea for a cool website (not that that doesn’t work for some people). Anyway, over the past two weeks I’ve devoured the free Django Book in an effort to understand the Django framework for web development. Consider me your personal plumber, and I’ll remove the porcelain toilet tank cover of the web and point out some of the major features.
Websites that are interesting these days are dynamic pages that do way more than displaying static content (Although there is a special place in my heart for a simple html page with an under construction .gif). The magic behind all of the functionality in modern websites lies in the programming that has gone on behind the scenes. Django is a framework for web development built on the programming language called Python, and it consists of three parts: urls, views, and templates.Urls are everything that comes after the .com up at the top of your browser. Django takes this string of characters and figures out what program is supposed to run. When you make your website, you create a list containing each url you want to exist, and pair it with a program (called a view) to run whenever that url is visited.
Views are the real meat of your website. This is where you get to manipulate data, make calculations, and do all the things that make your website interesting. They get their information from the url that called them and from the information stored in the website’s database (a big file somewhere) and then do whatever it is they’re supposed to do.
Templates generate what the user sees when they visit a website. When a view is all done with its calculations, it calls a template and gives it the information for the template to dress up. The template is just an html document with a bunch of blanks in it that get filled in with the output of the views. Django takes the answers, fills in the blanks, and then sends the document to the browser to display.
So here's an example:
- You navigate to www.example.com/welcome/', Django sees ‘/welcome/’ and runs the program ‘my_welcome_view’
- ‘my_welcome_view’ looks up what user just logged on and saves the name ‘James’ for later
- The template ‘Welcome to the site {{ name }}’ becomes ‘Welcome to the site James’ and shows up in your browser.
It also reduces having to write the same code in different places, since you can write one view that gets used with more than one url or have flexible templates that can be used in many places.
The final cool thing about working in Django and Python is that they are both designed so that you can iterate your website quickly. Python doesn’t need to be compiled and there is an interactive interpreter so you can play around and try little pieces of code without any trouble. Django takes this even further by providing you with a development web server that instantly reflects changes you make to your website. This means as soon as I add a piece to my site I can switch over to my browser and see what it looks like.
If you want to know more check out the fantastic book or drop me a line. Also stay tuned for my details on the first website I’m going to make in Django.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=091f6347-93d4-4f84-90b9-78f66c48efa4)
This posting has left me confused and aroused.
ReplyDelete