Python Indentation

Louis SanchezAugust 15th 2021, 12:06
A block is a group of statements that are meant to be executed together. In Python, statements are grouped using whitespace, that is, blocks are indented within other blocks instead of using curly braces. if True: # execute this block of statements print("Block 1") else: # execute other block of...

Python Comments

Louis SanchezAugust 15th 2021, 8:01
Comments are an integral part of programming. There are three different ways to write Python comments, documentation strings (docstrings for short), inline comments, and block comments. Block Comments Step 1 : Block and inline comments start with a pound sign, #. A block comment comes in the line before the...

Python User Input

Louis SanchezAugust 15th 2021, 1:55
User Input from the Keyboard Python has a very handy function for obtaining user keyboard input from the CLI called input(). When called, this function allows the user to type input into your program using their keyboard. Step 1 : Declare the following variable: message = input() The program execution...

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

Louis SanchezAugust 14th 2021, 10: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

Louis SanchezAugust 14th 2021, 11:59
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

Louis SanchezAugust 15th 2021, 7:25
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

Louis SanchezAugust 15th 2021, 12:00
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

Louis SanchezAugust 15th 2021, 11:08
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

Louis SanchezAugust 15th 2021, 12:47
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

Louis SanchezAugust 15th 2021, 12:02
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 }}...