Beginning a thread🧵 about the basics in #Python you need to know for #Django👇

Django is a #webframework to build interactive #websites for Python and is great for fast #development
1/ 19 Variables are used to store information, so that they can be used later on in your code.
In Python a ‘string’ is text and a ‘integer’ or ‘float’ is a number
‘car_brand’ and ‘brand_type’ are variables in the example below

Variables can be stored inside other variables
No special signs are allowed to be used in the name of variables, except for ‘_’ like.
Numbers are allowed in the name of a variable, but not at the start
So ‘1car’ is not OK and ‘car1’ is OK.

Lists store multiple pieces of information in a specific order.
A list always starts and ends with a square bracket ‘[‘ ‘]’.
Python starts counting at 0.
So the position or index number of the first item in the list is 0.
to print the first item, use #Code1
We can add items to the list by using the ‘append’ function.
See #Code2
A ‘for loop’ or looping allows you to perform the same action for multiple items in a list or group of items
A Tuple contains multiple items like a list.
The big difference is that a Tuple is immutable.
Which basically means you can’t change the values in a tuple
Unlike a list which is mutable or changeable
A dictionary is similar to a list.
It contains a set of item, but each item is associated with a key.
See below
The part before the colon is the ‘key’ and the part after the colon is the ‘value’
Together they are called a ‘key-value pair’.
The if statement is used in python when the program has to consider conditions
And reply in a certain way depending on the condition
While loops

The while loop continues the loop as long as a condition is valid
This code will continue to print the variable number
Adding 1 to the value in every iteration
Until the value 5 is reached
A function is a block of code that is written for a specific job
The function can be called by using the name of the function
Here’s an example

Functions part two

A keyword argument is a name-value pair, which directly links the argument to the parameter inside a function allowing to ignore the order inside a function.


A class defines the type of information an object can store and what functions it can do
Here’s an example

A class can use attributes and methods from another class. This is called inheritance.
BASIC DJANGO - now let's get into django

Best practice is to install django in a virtual environment
A virtual environment is an isolated environment where you can develop safely without

Create a project
To start with django you need to create a project, app, database and server

Include the app in the file inside your project.
Django doesn’t know our app exists yet, this way we tell django that there is an app called ‘myfirstapp’
15/19 Django is structured as follows.
When a user types

This is what happens: -> -> Model(if there is one) -> template
The contains the location of the page
the contains the content of the page
The contains the data of the page
The template contains the structure and styling of the page

Create the content of your page in the file inside your app
Create an ‘’ file inside your app and configure the links inside the app
Create a ‘templates’ folder inside your app. Create a home.html file inside your text editor with the following html tag: <h1> Hello </h1>. Put the file ‘home.html’ inside your templates folder.
This time go to the file in your project, not your app and include a reference to the file of your app. Don’t forget to write ‘include’ after ‘path’ on the import line.
you have learned how to create a basic django structure with one webpage

• • •

Missing some Tweet in this thread? You can try to force a refresh

Keep Current with Raza Zaidi

Raza Zaidi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!