Django Beginners Telusko
Learn More →
- What is Django? – 00:05
- Django Setup – 05:05
- First App in Django (Part-1) – 16:03
- First App in Django (Part-2) – 24:21
- Django Template Language (DTL) (Part-1) – 31:57
- Django Template Language (DTL) (Part-2) – 40:31
- Addition of two Numbers in Django – 44:15
- GET vs POST HTTP Methods – 52:24
- Model View Template (MVT) – 58:19
- Static Files 1 – 01:04:02
- Static Files 2 – 01:11:14
- Passing Dynamic Data in HTML (Part-1) – 01:21:05
- Passing Dynamic Data in HTML (Part-2) – 01:31:46
- If Statement in Django – 01:41:30
- Object Relational Mapper (ORM) – 01:46:52
- Postgres and PgAdmin Setup – 01:51:20
- Models & Migrations – 01:56:15
- Re-Migration – 02:08:14
- Admin Panel – 02:10:58
- Add & Fetch Data from Database – 02:16:59
- User Registration in Django (Part-1) – 02:25:55
- User Registration in Django (Part-2) – 02:39:25
- Passing Message in Django – 02:49:27
- User Login – 02:56:00
- User Logout – 03:03:59
Happy Learning.
Image Not Showing Possible ReasonsLearn More →
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
The Python Package Repository (PyPi), using the pip tool, is the best way to get the latest stable version of Django.
:
In order to use Django you will have to install Python on your operating system. If you're using Python 3 then you will also need the Python Package Index tool — pip3 — which is used to manage (install, update, and remove) Python packages/libraries used by Django and your other Python apps.
This section briefly explains how you can check what versions of Python are present, and install new versions as needed, for Ubuntu and Windows.
Ubuntu Linux 20.04 LTS includes Python 3.8.5 by default. You can confirm this by running the following command in the bash terminal:
However, the Python Package Index tool (pip3) you'll need to install packages for Python 3 (including Django) is not available by default. You can install pip3 in the bash terminal using:
Windows doesn't include Python by default, but you can easily install it
The Windows installer incorporates pip3 (the Python package manager) by default. You can list installed packages as shown:
VIRTUALENVWRAPPER_PYTHON and VIRTUALENVWRAPPER_VIRTUALENV_ARGS variables point to the normal installation location for Python3, and source /usr/local/bin/virtualenvwrapper.sh points to the normal location of the virtualenvwrapper.sh script. If the virtualenv doesn't work when you test it, one thing to check is that Python and the script are in the expected location (and then change the startup file appropriately).
You can find the correct locations for your system using the commands which virtualenvwrapper.sh and which python3.
Then reload the startup file by running the following command in the terminal:
Installing virtualenvwrapper-win is even simpler than setting up virtualenvwrapper because you don't need to configure where the tool stores virtual environment information (there is a default value). All you need to do is run the following command in the command prompt:
Once you've installed virtualenvwrapper or virtualenvwrapper-win then working with virtual environments is very similar on all platforms.
Now you can create a new virtual environment with the mkvirtualenv command.
When the command completes the new virtual environment will be active — you can see this because the start of the prompt will be the name of the environment in brackets, as below.
Now you're inside the virtual environment and can install Django to start developing.
There are just a few other useful commands that you should know (there are more in the tool documentation, but these are the ones you'll use regularly):
deactivate — Exit out of the current Python virtual environmentworkon — List available virtual environmentsworkon name_of_environment — Activate the specified Python virtual environmentrmvirtualenv name_of_environment — Remove the specified environment.Once you've created a virtual environment, and called workon to enter it.
And then use pip3 to install Django.
You can test that Django is installed by running the following command (this just tests that Python can find the Django module):
Now let's create a skeleton project and see it working. To do this, first navigate in your command prompt/terminal to where you want to store your Django apps. Create a folder for your test site and navigate into it.
You can then create a new skeleton site called "mytestsite" using the django-admin tool as shown. After creating the site you can navigate into the folder where you will find the main script for managing projects, called manage.py.
We can run the development web server from within this folder using manage.py and the runserver command, as shown.
Once the server is running you can view the site by navigating to the following URL on your local web browser: http://127.0.0.1:8000/. You should see a site that looks like this:
You now have a Django development environment up and running on your computer.
Following installation steps from official site postgresql.org or as below:
You should be prompted to create a new Linux password for postgres user.
Now that PostgreSQL is installed, to access its interactive shell and manage databases, you need to log in as the postgres user. To do so run the commands below:
You should now be in the interactive shell. By default there is a superuser role postgres.
You may set a password for this role as below:
Follow installation steps from official site pgadmin.org or as below:
After opening pgadmin, we can create a new sever as below:
You may give any valid name for the server.
In the Connection tab the username is actually one of the PostgreSQL roles. We are using the default postgre superuser role.
Finally, we created our first server using pgadmin4.
After PostgreSQL is installed, you can confirm that the PostgreSQL service is active, running and is enabled under systemd using the following systemctl commands:
Also, confirm that the Postgresql server is ready to accept connections from clients as follows:
Django uses MVT (Model-View-Template).
In MVT architecture, Model is similar to the model component of MVC wherein it is used to manage data. However, the business logic is managed by the View instead of the Model. Template is a HTML document that uses the Django Template Language (DTL).
Here's what happens once Django accepts the client request :-
The same is illustrated as given below.
Abhishek Dev