How Much Python Is Needed To Learn Django?


How Much Python Is Needed To Learn Django?

Django is a powerful and feature-rich web application framework - it is a great choice for beginners as it is a mature, well-organized, well-documented project with a wonderful community. But while the Django Project has some great tutorials that will help you get started with it, there are some essential prerequisites that you must learn before you begin your journey towards mastering Django.

To learn Django you will need to be familiar with at least the basics of Python: variables, data types, classes and functions, control flow and exception handling. You should be able to install packages with pip and run basic commands on the command line.

In this article I’ll summarize all the basic pieces of knowledge you’ll need to get started with Django, and point you to some useful resources, where you can pick up the necessary skills in each topic. This is not a complete guide, but rather meant to be used as a roadmap towards being able to build your first web app with Django.

If you are just starting to learn Python, or you are completely new to programming some concepts mentioned here might sound foreign, but don’t get discouraged: it’s completely fine if you don’t understand everything here on first read. You can bookmark this page and use it as a reference or checklist to keep you on track while learning Python.

Variables, Basic Data Types, Operators

Why Is It Needed?

There is nothing really Django-specific about these: if you are planning to do any programming, you must know these basics.

What You Need To Know

  • what is a variable, how to define and use them
  • the concept of global and local scope
  • the concept of data types
  • the most common data types in Python: string, int, float, list, tuple, dict, bool
  • the basic operators for the above mentioned data types: arithmetic operators, assignments, comparisons, string and array operations (slicing, indexing, concatenation, etc.), boolean operators

Where To Learn?

Control Flow: Loops, Conditionals, Comprehensions

Why Is It Needed?

These concepts still belong to the basics of programming: you must be comfortable with these language constructs to do anything beyond trivial scripts.

What You Need To Know

Basic Boolean Expressions

You need to be familiar with the basics of boolean algebra and the boolean and comparison operators in Python: and, or, not, in, is, =, >, < etc.

Conditionals

For your app to produce any useful behaviour, it’ll need to make decisions based on user input/some external data. To be able to do that you’ll need to read up on how if, elif and else works.

Loops

Get familiar with the concept of loops. Regarding the syntax, Python makes it easy for you, the two essential keywords are while and for, if you’re comfortable with them, you’ll be fine. Additionally, you might also want to look into how the range builtin works.

Comprehensions

List and dictionary comprehensions are just a fancy way of writing loops, but it is used extensively in Python, so don’t skip this one. They might look weird at first, but these are extremely powerful and quite elegant constructs.

Where To Learn?

Functions, Arguments

Why Is It Needed?

So far you’ve learned most of the necessary basics of the language, there are some structures though to help you organize your code: functions, classes, modules and packages.

What You Need To Know

  • Defining and using functions and methods
  • Positional and keyword arguments
  • Return values
  • Variable scopes

Where To Learn?

  • Python functions - nice, terse summary, pretty much all the basics you need to know in the beginning

Classes

Why Is It Needed?

Classes are extremely important tools for better organizing your code - especially in larger projects. Django uses classes extensively, so it’s a must for Django app development.

What You Need To Know

  • Classes and objects
  • Instance and static methods
  • Inheritence
  • Multiple inheritance

Where To Learn?

  • The official Python docs - the official Python docs has a comprehensive summary on classes, technically it contains all the information, so if you come from another programming language and you are already familiar with OOP concepts it should be more than enough. If you are new to OOP though you'll probably need a more thorough explanation
  • A more in-depth, but beginner-friendly explanation of OOP Python. - try this one if you're new to object-oriented programming

Packages, modules, pip

Why Is It Needed?

You’ll also need to install Django, and potentially other packages. Further down the road you might want to publish your own django apps as reusable packages. You’ll need to understand how modules work, and be able to import functions and classes from other modules.

What You Need To Know

  • What’s a module, how the import statement works in Python
  • What’s a Python package
  • Basic pip usage: how to install and update packages

Where To Learn?

Exception handling

Why Is It Needed?

In some cases Django will raise errors, that you’ll want to handle gracefully. Some examples, where you’ll need to know your way around exceptions: 404 pages, validation errors, database errors etc.

What You Need To Know

  • What’s an exception and how to handle it properly

Where To Learn?

Other Skills Besides Python

If you want to create an app with Django, you’ll need to be familiar with a few basic concepts and technologies apart from Python.

Basic Command Line Skills

Why Is It Needed?

You’ll need to run a few basic command to install Django, initialize and manage your app.

What You Need To Know

Just the absolute basics: start a console, and copy-paste commands from the docs :-) Doesn’t hurt to know what command line arguments are and how they work.

Where To Learn?

It depends on your operating system:

Css, Html

Why Is It Needed?

Most likely you will use Django to generate html code. Html will be your way to communicate with the web browser.

Plain html can be used to transfer pure information, so it will be displayed as a basic black and white page. Css is the technology that can be used to style your webpages - add colors, fonts, borders, etc.

What You Need To Know

What is markup, the basics of html and css. This is a bit of rabbit hole, as website design and frontend development is a huge topic in itself. However, for now you can keep it simple, and just learn the basics and come back to it later - or pick up more things as you go.

Where To Learn?

Client-Server Model, Frontend vs. Backend Code

Why Is It Needed?

I want to point out the importance of having a good understanding of this concept, because this is often a source of confusion among aspiring web developers. It is also a prerequisite to understand the basics of the http protocol.

What You Need To Know

Understand the role of a webserver/application server and the web browser, server-side vs client side clode, request/response flow.

Where To Learn?

Basics of Http

Why Is It Needed?

In Django you will deal with http requests and responses all the time.

What You Need To Know

  • Request-response messaging pattern
  • Basics of http protocol
  • How query parameters work
  • Most common http verbs (GET, POST, PUT, DELETE, etc.)
  • Most common http headers
  • Most common http status codes (200 OK, 404 Not found, 500 server error, etc.)
  • Some common encodings (base64, url encoding, JSON)

Where To Learn?

  • JSON - Wikipedia article on JSON
  • Urlencode tutorial - quick overview from w3schools
  • Base64 - Base64 encoding on wikipedia
  • Http - a quick overview of the http protocol
  • Http - collection of http tutorials (more than you need in the beginning, bookmark and come back to this later or if you get stuck)

How Long Will It Take to Learn All The Prerequisites For Django?

Learning all the basics of Python to be able to start with Django could take you a few month, but definitely should not take more than 6 month to 1 year.

If you are completely new to programming I’d advise you to take your time and build a solid foundation by learning the basics of Python.

You can read a more detailed breakdown here.

Is It Possible to Learn Django Without Knowing Python?

If you are an experienced developer already professional in at least one other programming language and have worked with web frameworks before, you might be fine with jumping right into Django and figuring out Python as you go.

Is It Worth The Effort? Should You Learn Python/Django?

It might seem like a lot of work, but Python is the 2nd most popular programming language and Django is in the top 5 among the most popular web framework.

There are an overwhelming amount of job opportunities for software engineers, who know their way around Python and/or Django, so it is absolutely worth the effort.

If you’re still not convinced, or want to learn more, check my full article on the topic: Is Django worth learning?

References