Programming Articles - Page 1114 of 3363

Creating a screenshot taking website in Django

Ath Tripathi
Updated on 25-Aug-2021 12:55:43

902 Views

In this article, we will see how to create a screenshot taking website in Django. This website will basically take the screenshot of our screen whenever we click "take screenshot". It then will store the screenshot in our media folder and we can view it whenever we want.ExampleSo let's start by creating a project and an app.In settings.py, in INSTALLED_APPS add your app name, and add this code at the bottom −MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR/'media'We just setup our basic media folder for our image uploading purpose.Now in project's urls.py −from django.contrib import admin from django.urls import path, include ... Read More

Client side image zooming and rotating in Django

Ath Tripathi
Updated on 25-Aug-2021 12:50:15

685 Views

Sometimes, we may need to rotate an image or zoom it. In such cases, a client-side image zooming library is used to add jquery feature of zooming-rotating on html file. We just needed to load jquery js and css in html file.Create a Django project and an app. Setup urls and do some basic stuff like adding app in INSTALLED_APPS.Install the django-client-side-image-cropping librarypip install django-client-side-image-croppingNow in settings.py, add the following line −INSTALLED_APPS+=['client_side_image_cropping']Here, we have done a simple setting of adding a module as an app.ExampleIn models.py, add the following lines −from django.db import models # Create your models here. ... Read More

Adding translation to a model instance in Django

Ath Tripathi
Updated on 25-Aug-2021 12:44:25

326 Views

In this article, we are going to learn how to create a translation for any instance. Sometimes, you may need to save data like ID, names, quotes, lines, etc. You may have to render that data in different languages; for that, you need to do a lot of database stuff, but today I will show you how to get the same result in just a few lines of setup.Create a Django project and an app. Setup urls and do some basic stuff like adding app in INSTALLED_APPS.Create a model. Here, we don't have much to do with views.py, urls.py or ... Read More

How to add a Money field in Django?

Ath Tripathi
Updated on 25-Aug-2021 12:37:19

2K+ Views

Sometimes, we may have to add money-related data in a website, like salary, fees or income. Django provides an integer field but many a time, it doesn't work like we want. So, for handling money field, we can use a third-package library that will add the money field to our model.Make a project and an app, I named it "MoneyFieldDemo" and "myapp".Set the basic things like urls and INSTALLED_APPS.And yes, install a library −pip install django-moneyAdd the following line in settings.py −INSTALLED_APPS+= ["djmoney"]ExampleIn app's, urls.py, add the following lines −from django.urls import path from . import views urlpatterns = ... Read More

Adding JSON field in Django models

Ath Tripathi
Updated on 25-Aug-2021 12:33:02

15K+ Views

In this article, we will see how to add JSON fields to our Django models. JSON is a simple format to store data in key and value format. It is written in curly braces. Many a time, on developer website, we need to add developer data and JSON fields are useful in such cases.First create a Django project and an app. Please do all the basic things, like adding app in INSTALLED_APPS and setting up urls, making a basic model and render its form in an HTML file.ExampleInstall the django-jsonfield package −pip install django-jsonfieldNow, let's create a model in models.py, ... Read More

How to add extra security to Django admin using fake admin login?

Ath Tripathi
Updated on 25-Aug-2021 12:31:17

407 Views

We are going to make a Django admin fake login page using a thirdparty package. This will just create a Django admin fake page, and whenever anyone tries to login on the admin page, whether they enter the right or wrong password, they will not be able to login and their trial with their IP addresses will be stored in a table.So, just follow the steps given below and you will be all good to go.Setup basic urls and add app in INSTALLED_APPS in settings.py.ExampleFirst install the packagepip install django-admin-honeypotIn settings.py, add this −INSTALLED_APPS+ = ['admin_honeypot']We simply add it to ... Read More

How to add Django debug toolbar to your project?

Ath Tripathi
Updated on 25-Aug-2021 12:18:58

3K+ Views

Django toolbox is a debugging tool that is used to debug database queries, Django website loading speed, and many other things. Debug toolbar is very popular among developers and everyone is using it. So, let's dive into to see how to implement it.ExampleCreate an app with the name "myapp".First, install the django-debug-toolbar −pip install django-debug-toolbarNow, add 'debug_toolbar' to your INSTALLED_APPS in settings.py −INSTALLED_APPS = [    # ...    'debug_toolbar',    'myapp' ]This will add the debug toolbar as an app in our project.Next, in your middleware, add the following −MIDDLEWARE = [    # ...    'debug_toolbar.middleware.DebugToolbarMiddleware',    # ... Read More

PHP – How to get the substitution character using mb_substitute_character()?

Urmila Samariya
Updated on 23-Aug-2021 08:34:59

321 Views

In PHP, we can use the function mb_substitute_character() to get the substitution character. This function specifies the substitution character when the input character encoding is not valid or the character code does not exist in the output character encoding.Note: The invalid characters may be substituted with no output, string, or int value (Unicode character code value).Syntaxstring mb_substitute_character($char)ParametersThis function accepts only one parameter, $char.$char− It specifies the Unicode value as an integer or the strings given below:"none"− It will return no output."long"− It is used for the output character code value. For example, "U+3000, JIS+7E7E""entity"− it is used to return the output ... Read More

PHP – Get the string length using mb_strlen()

Urmila Samariya
Updated on 23-Aug-2021 08:34:29

2K+ Views

In PHP, multibyte string length (mb_strlen) function is used to get the total string length of a specified string. This function is supported in PHP 4.6.0 or higher versions.Syntaxint mb_strlen(str $string, str $encoding)Parametersmb_strlen() accepts two parameters: $string and $encoding.$string− It is used to check the string length$encoding− This parameter is used for character encoding. If it is omitted or null, then the internal character encoding value will be used.Return Valuesmb_strlen() returns the number of characters present in the given string. One is counted as a multi-byte character.Errors/ExceptionsIf the encoding is not known, then it will generate the level E_warning.Example Live DemoOutputTotal ... Read More

PHP – How to set the character encoding detection order using mb_detect_order()?

Urmila Samariya
Updated on 23-Aug-2021 08:33:52

258 Views

The mb_detect_order() function in PHP can be used to set/get the character encoding detection in an order. This function is supported in PHP 4.2.0 or higher versions.Syntaxarray|bool mb_detect_order(str $encoding)Parametersmb_detect_order() accepts only one parameter $encoding with string, array and bool.$encoding− This encoding parameter is an array or comma-separated list of character encoding. If it is omitted or null, then it returns the current character encoding detection order as an array.Return ValuesWhen setting the encoding detection order, it returns True on success or it returns False on failure.Example Live DemoOutputASCII, JIS, EUC-JPRead More

Advertisements