Python web framework — models, templates, QuerySets, PostgreSQL and deployment — written by Aivasu Tech Institute's mentors. Free to read, structured to actually help you learn.
Django notes by Aivasu Tech Institute cover 55 topics — from django home to add bootstrap 5 — each explained with short definitions, syntax and runnable code examples. They are 100% free, need no signup, and work as quick revision for college exams, Django interviews and Aivasu Tech Institute's mentor-led Django course in Pitampura, Delhi.
No notes found. Try a different search term, or browse all Django notes.
Django is a back-end server side web framework.
Django is a Python framework that makes it easier to create web sites using Python.
Note: To install Django, you must have Python installed, and a package manager like PIP. PIP is included in Python from version 3.4.
It is suggested to have a dedicated virtual environment for each Django project, and one way to manage a virtual environment is venv, which is included in Pytho
Now, that we have created a virtual environment, we are ready to install Django.
Once you have come up with a suitable name for your Django project, like mine: my_tennis_club , navigate to where in the file system you want to store the code
An app is a web application that has a specific meaning in your project, like a home page, a contact form, or a members database.
Django views are Python functions that take http requests and return http response, like HTML documents.
Create a file named urls.py in the same folder as the views.py file, and type this code in it:
In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let's do that.
A Django model is a table in your database.
The Members table created in the previous chapter is empty.
To update records that are already in the database, we first have to get the record we want to update:
To delete a record in a table, start by getting the record you want to delete:
To add a field to a table after it is created, open the models.py file, and make your changes:
After creating Models, with the fields and data we want in them, it is time to display the data in a web page.
The next step in our web page will be to add a Details page, where we can list more details about a specific member.
In the previous pages we created two templates, one for listing all members, and one for details about a member.
The main page will be the landing page when someone visits the root folder of the project.
If you try to access a page that does not exist (a 404 error), Django directs you to a built-in view that handles 404 errors.
When testing different aspects of Django, it can be a good idea to have somewhere to test code without destroying the main project.
Django Admin is a really great tool in Django, it is actually a CRUD user interface of all your models!
To be able to log into the admin application, we need to create a user.
To include the Member model in the admin interface, we have to tell Django that this model should be visible in the admin interface.
Make the List Display More Reader-Friendly
Now we are able to create, update, and delete members in our database, and we start by giving them all a date for when they became members.
To add a new member, click on the "ADD MEMBER" button in the top right corner:
To delete a new member, you can either select a member and choose the action "Delete selected members" like this:
In Django templates, you can render variables by putting them inside {{ }} brackets:
In Django templates, you can perform programming logic like executing if statements and for loops.
An if statement evaluates a variable and executes a block of code if the value is true.
A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.
Comments allows you to have sections of code that should be ignored.
The include tag allows you to include a template inside the current template.
A QuerySet is a collection of data from a database.
There are different methods to get data from a model into a QuerySet.
The filter() method is used to filter your search, and allows you to return only the rows that matches the search term.
To sort QuerySets, Django uses the order_by() method:
When building web applications, you probably want to add some static files like images or css files.
Django does not have a built-in solution for serving static files, at least not in production when DEBUG has to be False .
Static files in your project, like stylesheets, JavaScripts, and images, are not handled automatically by Django when DEBUG = False .
We have learned how to add a static file in the application's static folder, and how to use it in the application.
If you have followed the steps in the entire Django tutorial, you will have a my_tennis_club project on your computer, with 5 members:
Django comes with a SQLite database which is great for testing and debugging at the beginning of a project.
Inside the RDS service, create a database, either by navigating to the Database section, or just click the "Create database" button:
To make Django able to connect to your database, you have to specify it in the DATABASES tuple in the settings.py file.
The "My Tennis Club" project has no members: 127.0.0.1:8000/ .
To deploy a project means to make it visible for other people on the internet.
When you create a Django application, there are some Python packages that your project depends on.
We have chosen AWS as our hosting provider, and Elastic Beanstalk as a service to deploy the Django project, and it has some specific requirements.
To wrap your project into a .zip file, you cannot zip the entire project folder, but choose the files and folders manually.
In AWS, navigate to the Elastic Beanstalk application, as we did in the Choose Provider chapter, and click the "Create application" button:
Any changes you do with the application locally, on your own computer, is not visible on the deployed version.
Join Aivasu Tech Institute's Django course — live mentorship, hands-on projects, and 100% placement support in Delhi NCR.
Enroll Now — Free Demo Available✳ Common questions
What students search before reading Django notes.