Found 33676 Articles for Programming

How to sort 0,1 in an Array without using any extra space using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 12:24:44

410 Views

Take two-pointers, low, high. We will use low pointers at the start, and the high pointer will point at the end of the given array.If array [low] =0, then no swapping requiredIf array [low] = 1, then swapping is required. Decrement high pointer once.Time complexity − O(N)Example Live Demousing System; namespace ConsoleApplication{    public class Arrays{       public void SwapZerosOnes(int[] arr){          int low = 0;          int high = arr.Length - 1;          while (low < high){             if (arr[low] == 1){     ... Read More

How to sort 0,1,2 in an Array (Dutch National Flag) without extra space using C#?

Nizamuddin Siddiqui
Updated on 27-Aug-2021 12:25:16

246 Views

We need to take three-pointers, low, mid, high. We will use low and mid pointers at the start, and the high pointer will point at the end of the given array.If array [mid] =0, then swap array [mid] with array [low] and increment both pointers once.If array [mid] = 1, then no swapping is required. Increment mid pointer once.If array [mid] = 2, then we swap array [mid] with array [high] and decrement the high pointer once.Time complexity − O(N)Example Live Demousing System; namespace ConsoleApplication{    public class Arrays{       private void Swap(int[] arr, int pos1, int pos2){   ... Read More

Using djoser in Django for token authentication without views

Ath Tripathi
Updated on 26-Aug-2021 13:26:54

2K+ Views

Djoser is a simple authentication library for Django. It is used to generate tokens for authentication; this generated token is generated by taking three fields: username, email and password. It only works on POST request, but you can add its frontend.ExampleCreate a Django project and an app. I named them "DjoserExample" and "myapp".Install two packages −pip install djoser pip install djangorestframeworkIn settings.py, add the following lines −INSTALLED_APPS = [ #below every other apps    'myapp',    'rest_framework',    'rest_framework.authtoken',    'djoser' ] # Below template variable REST_FRAMEWORK = {    'DEFAULT_AUTHENTICATION_CLASSES': (       'rest_framework.authentication.TokenAuthentication',    ),   ... Read More

How to add Social Share buttons in Django?

Ath Tripathi
Updated on 26-Aug-2021 13:23:46

3K+ Views

We get to see Social Share buttons on most of the websites. They play an important role in ecommerce or any blogging or affiliate sites. As a web developer, you surely want people to like your website and want them to tell about your site to others on social media.In this article, we will see how to make an automated website share social button.ExampleFirst of all, create a project and an app.Install the django-social-share package −pip install django-social-shareIn settings.py, add django_social_share as an app in project.INSTALLED_APPS += ['django_social_share']In project's urls.py −from django.contrib import admin from django.urls import path, include ... Read More

Smooth profiling in Django

Ath Tripathi
Updated on 26-Aug-2021 13:22:21

546 Views

In this article, we are going to make a Django profiling. It will show a great deal of information like the total number of GET requests, database queries and many other reports for your website on a URL endpoint. It is great in production because you need to keep a check on many things when your site is in production.It is a great resource if you have to deploy a real-world project.ExampleFirst of all, create a project and an app. Do some basic settings and set up the urls.Now, install the djnago-silk package −pip install django-silkIn settings.py, add the following ... Read More

Django – Showing model data directly into table with sorting and pagination

Ath Tripathi
Updated on 26-Aug-2021 13:20:45

2K+ Views

In this article, we will see how to make a table in Django which will render model data. We are not going to use the tag of html. We will use a simple Django table library which provides features to directly show Django model data in a table with pagination feature.ExampleFirst of all, create a project and an app and set up the urls.Install the django_tables2 package −pip install django_tables2In settings.py −INSTALLED_APPS+=["django_tables2"]In models.py, create a simple model for testing −from django.db import models # Create your models here. class Data(models.Model):    Name=models.CharField(max_length=100)    salary = models.CharField(max_length=20)In urls.py, add ... Read More

QR code generating website in Django

Ath Tripathi
Updated on 26-Aug-2021 13:16:49

2K+ Views

We sometimes need to generate the QR code of an URL in our website. QR codes are scanned for verification, website login, opening websites and many things like that. In this article, we will see how to implement that. We are going to create a qrgenerator website in Django.ExampleCreate a Django project and an app. Create a media folder at the same level of project and app.Go to settings.py in the project folder and add the app name in INSTALLED_APPS and add this at the bottom −MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') MEDIA_URL = '/media/'Here we set up our media folder where ... Read More

Model object's history tracking in Django

Ath Tripathi
Updated on 26-Aug-2021 13:10:44

3K+ Views

Model history tracking is a feature which tracks the changes in model object, it tracks things like what change you made in it and when you deleted it. It also helps in the recovery of deleted object of model. In this article, we will take an example to see how to track a model object's history in Django.ExampleFirst of all, set up your project, apps, urls and a model.Install the django-simple-history library −pip install django-simple-historyIn settings.py −INSTALLED_APPS+=[" simple_history"] MIDDLEWARE = [    #other middle ware    'simple_history.middleware.HistoryRequestMiddleware', ]Here we added the "simple_history" module as app and a middleware.Here we don't ... Read More

How to add an UpdateView in Django?

Ath Tripathi
Updated on 14-Mar-2022 06:03:52

3K+ Views

UpdateView is a view in Django which is used to update any model data from frontend. It is a built-in view that can be easily applied. It acts like an Admin page in updating the view. In this article, we will take an example and demonstrate how to use UpdateView in Django.First of all, create a Django project and an app. I created the project with the name "tutorial11" and the app with the name "modelFormsDemo".Now, let's do some basic things.Add app in settings.py −INSTALLED_APPS+ = ['modelFormsDemo']In project's urls.py, include app's urls.from django.contrib import admin from django.urls import path, include ... Read More

How to add a text editor field in Django?

Ath Tripathi
Updated on 26-Aug-2021 13:04:16

2K+ Views

Many online exam taking websites use text editors for text entries. image uploading, etc. Quill text editor is very popular and it also provides a model field to directly store in database. So, you don't need to configure anything extra to save its data in database.In this article, we will see how to make a text editor field in Django.First of all, create a Django project and an app. Do some basic settings like including urls of app. Create a media folder at the same level of project and app.In settings.py, add −INSTALLED_APPS = [ 'myapp.apps.MyappConfig', #django app ' django_quill' ... Read More

Advertisements