DjangO 3
for beginners
Dedication
Thank you Dominique Zillmann, for broadening my understanding of the world, the true face of the human kind. I had great fun all over Spain. Ah and, bfb nutt.
A big thank you goes to my parents, for supporting me in every possible way on every journey.
The most applause goes to me. For being awesome, cute, perfect and very humble. Couldnt have done it without you.
Foreword
Im glad youve made it this far. In this book, you will learn to create a web application with Django 3, a web framework for the Python programming language. You will learn the essential web development concepts and all the necessary information to get started with Django 3. But before Django 3, we will learn the basic concepts of programming and the Programming Language Python 3.9.
We will build a blogging web application with added features. Users will be able to post blogs. The application will also have a feature that allows users to post questions and provide answers to them.
Our blog application will be focused on the theme of finance; that is, our blogs will be focused on finance and how people can improve their finance, do their taxes, tips on savings, etc. Our question/answer section will be focused on finance, as well.
If you note, you can convert this application to any theme you like, i.e., tech, writing, etc. We, however, will be making this blog a website that focuses on finance.
By the end of this book, youll have enough knowledge in Django 3 and web development, in general, to build web apps on your own. Youll also know how to deploy your Django 3 Application in a Serverless Environment in a Cloud.
About this book
This book is designed to be used both digital and printed. Therefore, I have made plenty of screenshots for people who like to read the book (ebook and printed) without immediately implementing the code. This ensures a smooth and hassle-free reading experience.
If, on the other hand, you want to learn the contents as quickly as possible, you can clone the official GitHub repository and save time. I highly recommend you not to use the GitHub repository at the beginning of this journey, especially if you are new to Django. Type the code symbol by symbol yourself. You can find the Github Repository: https://github.com/AndreyBulezyuk/Django-3-Book.
This ensures that you fail quickly in the beginning and learn about the common pitfalls (like forgetting to execute the migrations, not updating the Entity, etc.). You deprive yourself of this learning opportunity when simply clone the code.
The structure of the content is somewhat different from other programming books. Its a mix of theory and practice where practice comes first, and the theory bits are injected into the sub-steps. This ensures that you learn the practical and real-world workflow of building a Django Website. And while you are practicing it, you are learning the theory in tiny-sized bits just at the right time. This way, you wont be overwhelmed by the dry theory. I genuinely believe that this format will have the best impact on your learning journey.
Scientific literature has shown that the best way to learn is by doing, so always try to solve the problems at the end of the chapter. If you are having difficulty solving some of them, do not worry nobody said programming was easy, remember to take a break when you are feeling tired and be sure to go through the example problems and their solutions.
PYTHON 3
Introduction
This is an Introduction to Python 3, which means we will cover the Basics of Python3 and the basic concepts of programming. Python 3.9 is the current stable release, which means you will be learning the newest stuff there is.
Why Python?
Python 3 is easy to learn, it is the fastest growing language in the world, which means it has a large community behind it, it has thousands of different libraries with new ones being added every day, it is widely used for Machine Learning, Cloud Computing, Web Development, Web Scrapping, Desktop Development and pretty much anything you can think of (even Game & App Dev).
Python is an interpreted, object-oriented, high-level programming language. Interpreted means that every python code file is ready to go and does not require any additional steps to run it, object-oriented means that the language is designed with the intent of creating high-level complex abstractions called objects. Python by design is highly readable, that coupled with the large quantity of different libraries and a strong community is what makes it a beginner friendly language.
Syntax and Variables
What is a variable
Think of a variable as a name referring to an object. For example, consider you have a dog and you are describing him to a friend, when you say Max is a young puppy Max is just an identifier and every time you use the word Max what you are actually thinking of is the dog itself.
myDogName = 'Max' print ( myDogName ) myDogName = Max
In programming it is exactly the same - when writing myDogName what I actually am referring to is Max - the name of my dog. To see that this is the case we can simply use the print command to retrieve the content of the variable.
Basic Data Types in Python
In most programming languages the programmer must specify beforehand what type will the type of data stored in that variable be, the most common of those types are natural numbers (integers), decimal point numbers (floating point real values) and text (strings).
In Python this process is handled automatically and is hidden from the programmer and thus makes the code much easier to read. To see for yourself we will use the built-in type() function which gives us as a result the underlying type of the variable.
myString = "A great day to learn Python" print ( type ( myString )) myInt = print ( type ( myInt )) myFloat = 3.14 print ( type ( myFloat ))
Variable Manipulation
Variable Assignment
This is one of the most fundamental operations you will deal with as a programmer, since if variables are empty boxes, assigning a value to them is the act of filling them up. The assignment is done by using the equals (=) sign. To demonstrate how the assignment operator works and how the data type changes between assignments we will use the type and print functions we just discussed in the following example.
myVariable = print ( type ( myVariable )) myVariable = 10.1 print ( type ( myVariable )) myVariable = "Yes, I can do this" print ( type ( myVariable ))
In this example you can clearly see that variables are dynamic in nature, that is they do not have a predefined type or property they must adhere to. That is why I am first able to use the variable to hold a natural number, then a float, and then a string.
This leads us to another important aspect of the process of assignment, there are two parts to the assignment the Left-Hand Side and the Right-Hand Side or for short LHS and RHS, determined by which side of the equals sign they are situated. The LHS is the variable that is being assigned to while the RHS is what is being assigned .
In other words, the LHS is the box and the RHS is the data that goes into the box. Note that this is not exactly what is happening underneath the hood, in actuality everything in Python is an object and variable names point to these objects, but for now this is the analogy we will go with.
In the following example you will see that both the RHS and the LHS can be variables and thus our box-data analogy is not very clear, since both sides appear to be boxes. What assignment means in this case is that we want to copy the data contained in the RHS and just like before put that copy into the LHS box. Keep in mind copying the contents is not always the case, when we are dealing with objects, but more on that in Chapter Six.
Next page