Django 3 : Getting data from the database

Louis SanchezAugust 15th 2021, 5:07
Before using Django to retrieve data from a database, we were using SQL queries to retrieve an object containing the result. With Django, there are two ways to retrieve records from the database depending on whether we want to get back one or several records. Getting multiple records Step 1...

Django 3 : Creating an administration site for models

Louis SanchezAugust 15th 2021, 8:20
The administration module is very convenient and is included by default with Django. It is a module that will maintain the content of the database without difficulty. This is not a database manager because it cannot maintain the structure of the database. Installing the module Step 1 : The django.contrib.admin...

Django 3 : Creating our first model

Louis SanchezAugust 15th 2021, 1:15
Databases and Django Django can interface with many databases. However, during the development of our application, we use SQLite libraries that are included in Django. Step 1 : We will modify to set our connection to the database: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3',...

Django 3 : Using static files in templates

Louis SanchezAugust 15th 2021, 2:05
Static files such as JavaScript files, CSS, or images are essential to obtain an ergonomic website. These files are often stored in a folder, but they can be useful to modify this folder under development or in production. Step 1 : Django allows us to define a folder containing the...

Django 3 : Extending the templates

Louis SanchezAugust 14th 2021, 11:56
The legacy of templates allows you to define a super template and a subtemplate that inherits from the super template. In the super template, it is possible to define blocks that subtemplates can fill. We will use an example where the page.html template will extend the base.html template. Step 1...

Django 3 : Passing Variables to the template

Louis SanchezAugust 15th 2021, 3:38
Django 3 : Passing Variables to the template Injecting the data from the view to the template Before improving our template, we must send variables to the templates. The injection of the data is based on these variables, as the template will perform certain actions Step 1 : We will...

Django 3 : Displaying Hello world! in a template

Louis SanchezAugust 15th 2021, 10:47
Templates are files that will allow us to generate the HTML code returned to the client. Step 1 : We will create the first template of our application. To do so, we must first edit the file to define the folder that will contain our templates. import os #...

Django 3 : Routing and Creating our first view

Louis SanchezAugust 15th 2021, 12:07
Routing in Django Step 1 : In the previous post, we edited the file to configure our Django project. ROOT_URLCONF = 'myproject.urls' This parameter will define the Python file that will contain all the URLs of our site. When the controller receives the client request, it will go in...

Django 3 : Configuring the application

Louis SanchezAugust 15th 2021, 12:10
To configure our project or our application, we need to edit the file in the project folder. This file contains variables. These variables are the settings that Django reads when initializing the web app. The following are a few of these variables: Step 1 : DEBUG: This parameter must...

Django 3 : Creating a Django Project

Louis SanchezAugust 15th 2021, 12:11
Starting your project with Django Before you start using Django, you need to create an environment for your applications. We will create a Django project. This project will then contain our applications. Step 1 : To create the project of our application, we need to run the following command using...