What is Django?

Hopefully you are now asking yourself what does Django actually do and where does it fit into the image of the internet we were looking at in the last section.

Static vs. Dynamic Webpages

In order to understand what Django is and why we need it, we first have to understand the difference between a static website and a dynamic website. In this case the namers got it right because the difference between the two is more or less implied based on the names.

A static website is a website that does not dynamically load any pages. In other words, every page in this website is static; it is not specially generated by the server when it receives a request based on the client. Instead, every request it gets for a certain page will be answered with the same exact page.

In contrast, a dynamic website is one where pages can be loaded dynamically based on a user request by looking up a database and specially generating the page based on the information queried. To make it clear, lets consider two examples.

(Don't be fooled by the static nature of the Python3 documentation website; it is quite thrilling stuff to read)

Consider the Python3 Documentation. This website always displays the same thing, no matter the context within which it is being viewed. The context can entail the person looking, the time they are looking, where they are looking, etc. Thus, when we go to the website, all that the server has to do is send us the static files specifying the website and our browser takes it from there by rendering those static files into a webpage. This website is a static website.

(A Facebook profile page dynamically generated by Mark Zuckerburg just for me! It is so personalized that even the ads I get are for web development)

On the other hand, consider Facebook. On this website, no two users see the same page. Facebook loads different pages for different people based on a variety of factors, but most of all based on the account of who is looking. Consider the profile page specifically. If you go to "www.facebook.com/profile", facebook sends back a different page to you than it does to me. However, we would have both gone to the same URL. Thus, that means that when the request for "/profile" is sent to the "www.facebook.com" domain, the server, also located in Oregon (why is Oregon so popular), is going to receive the same request from you and me.

However, the client also sends over other information like our IP address, our account if we are logged into one, etc. With this identifying information, Facebook's server does the following:

  1. Query it's database for profile information specific to your account
  2. Pick and process relevant content to be displayed on your page
  3. Dynamically generate HTML to make the page render for your profile specifically
  4. Send the dynamically generated HTML, CSS, and Javascript to the client

As you can see, the process that a dynamic webpage goes through is much more complex than the process that a static web page goes through. In order to manage this complexity, we use web frameworks.

Dynamic Web Frameworks

Hopefully by now you see that static websites aren't the most invigorating websites in the world. As interesting as python documentation and your resume website is, dynamic websites are where it's at. 99% of the interesting websites in the world are living, breathing, dynamic websites that we are going to learn how to make in this guide. Part 1 is going to teach you the basics of HTML, CSS, and Javascript through static website development. Then in Part 2 we will learn all about making slick, solid dynamic websites using the Python web framework known as Django. But first, what is a web framework?

A web framework is a tool used by developers to easily implement the functionality described in the 4 step process above. In essence, those 4 steps are very annoying to do from scratch every time. And, as you can imagine, the plumbing of those 4 steps is highly invariable from website to website. Thus, overtime web developers began to reuse code from website to website and, finally, packaged this all together into the first every web framework. Now, instead of focusing on the nitty grittys of those 4 steps, we could build ontop of existing functionality and turn our efforts to cooler endeavors.

Another way to think about a web framework is to think about it as the code that runs on the servers sitting in Oregon from Google and Facebook. When we program our websites in Django, we are going to be writing code that sits on that server and tells the server what to do when it gets a request.

Django is a Python Web Framework

There are many web frameworks out there that use all sorts of different languages. Some big ones you might have heard of is Ruby on Rails and PHP. The first one is implemented in Ruby (ew) and the second on is implemented in PHP (triple ew). Because I (and everyone reading this, I am sure) pray at the altar or Guido, we are going to focus on Django, a web framework written in python.

Django isn't even the only python web framework. If you want there are others like Flask. The difference between all these different websites is that they are optimized for different sized websites and use cases. We are going to focus on Django for two reasons:

  1. Django is a powerful open source framework with a large community that builds nice module for it all the time. You can build any website you want with this framework.
  2. Mostly all web frameworks boil down to the same set of few key features. After learning Django you will be able to quickly jump into any other framework, such as Ruby on Rails, and get up to speed.

Conclusion

In summary, there are two types of website out there: (1) static websites that load pages the same for every user and (2) dynamic websites that interact with databases and then dynamically load pages based on a variety of factors. Modern day web development of dynamic websites occurs through web frameworks which abstract away the plumbing and make it easy to access powerful functionality. This course will specifically focus on the python web framework, Django.

If you have read and followed everything that I have talked about so far then you hopefully now have a much greater understanding and appreciation for how the internet works and what it might take to program a website that runs in it. From here on out we are going to dive into the development of actual websites and get our hands dirty with lots of code (don't worry, the amount of rambling you have to endure will go down from here on out too). Reading this book without actually coding along with me will be utterly useless. On the other hand, writing the code I ask you to do and learning along the way will result in a new skill set for you an a slick Intragram clone that we will be developing along the way. Good luck!

results matching ""

    No results matching ""