Django 3

How To Set Up Django with uWSGI, PostgreSQL and Nginx on Ubuntu 20.04

May 10th 2021, 6:52
We will install Django and all the components that are needed for Nginx and Django to be able to communicate. Install the Packages Step 1 : Install the Packages from the Ubuntu repositories sudo apt-get update sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx Setting up Django Step 2...

Django 3 : Creating and getting session variables

May 10th 2021, 12:13
With Django, storage in a database, generation of the hash code, and exchanges with the client will be transparent. Sessions are stored in the context represented by the request variable. To save a value in a session variable, we must use the following syntax: request.session['session_var_name'] = "Value" Once the session...

Django 3 : Create a Django form

May 11th 2021, 12:14
Django forms work with an object that inherits from the Form class. This object will handle much of the work we have done manually in the previous post. Step 1 : Add the following URL to your file: path('create-profile-forms', views.create_profile_forms, name="create_profile_forms"), Step 2 : We will create our view...

Django 3 : Create an HTML form

May 10th 2021, 6:52
In this post, we will show you how to add a profile without using Django forms. This example will show the time that can be saved by using Django. Step 1 : Add the following URL to your file: path('create-profile', views.create_profile, name="create_profile"), Step 2 : We will create a...

Django 3 : Deleting objects

May 10th 2021, 7:36
Deleting a record Step 1To delete a record in the database, we must use the delete() method. Removing items is easier than changing items, because the method is the same for a queryset as for the instances of models. An example of this is as follows from myproject.models import UserProfile...

Django 3 : Updating objects

May 10th 2021, 5:00
Updating a model instance Step 1Updating the existing data is very simple. We have already seen what it takes to be able to do so. The following is an example where it modifies the first profile: from myproject.models import UserProfile profile = UserProfile.objects.get(id = 1) = 'Updateing profile'

Django 3 : Creating objects

May 10th 2021, 4:25
Step 1 We can create the records in the UserProfile model as follows: from myproject.models import UserProfile profile = UserProfile(name='New Profile', login='newprofile') Step 2 : The code template {% extends "base.html" %} {% block title %} {{ action }} {% endblock %} {% block h1 %} {{ action }}...

Django 3 : Getting data from the database

May 10th 2021, 4:31
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

May 11th 2021, 3:42
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

May 11th 2021, 5:00
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',...