Python

Python Indentation

August 14th 2021, 4: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...
975

Python Comments

August 15th 2021, 12: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...
1107

Python User Input

August 15th 2021, 5: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...
1142

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

August 14th 2021, 2: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...
1917

Django 3 : Creating and getting session variables

August 14th 2021, 3: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...
842

Django 3 : Create a Django form

August 14th 2021, 11: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 urls.py file: path('create-profile-forms', views.create_profile_forms, name="create_profile_forms"), Step 2 : We will create our view...
1019

Django 3 : Create an HTML form

August 14th 2021, 4: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 urls.py file: path('create-profile', views.create_profile, name="create_profile"), Step 2 : We will create a...
814

Django 3 : Deleting objects

August 15th 2021, 3: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...
824

Django 3 : Updating objects

August 15th 2021, 4: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) profile.name = 'Updateing profile' profile.save()...
695

Django 3 : Creating objects

August 14th 2021, 4: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') profile.save() Step 2 : The code template {% extends "base.html" %} {% block title %} {{ action }} {% endblock %} {% block h1 %} {{ action }}...
644