Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1113 of 3363
3K+ Views
In many developer websites, we get to see Google social authentication which is very handy. In this article, we will see how to create a Django Google login project.First, go to https://console.cloud.google.com/apis/dashboardand create a project .Go to Oauth consent screen and create a screen and save & continue.Go to credentials and click "create credentials" and then "OAuth client ID":Then, select web application, and add these two URLs −http://127.0.0.1:8000/http://127.0.0.1:8000/accounts/github/login/callback/Now, you will get a client ID and a secret key, keep them safe in your file.ExampleCreate a Django project and an app.In settings.py −SITE_ID = 1 LOGIN_REDIRECT_URL = "/" INSTALLED_APPS = [ ... Read More
760 Views
In many developer websites, we get to see GitHub social authentication which is very handy. In this article, we will see how to add Github Auth in our Django website.Go to https://github.com/settings/developers/ and create an Oauth application and add these two URLshttp://127.0.0.1:8000/http://127.0.0.1:8000/accounts/github/login/callbackThen, you will get a Client ID and a secret key. Now, let's move to the coding part.ExampleInstall the django-allauth library −pip install django-allauthIn settings.py add the following lines of code −INSTALLED_APPS = [ ################## # # # # 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.github', 'githubAuthentication' ] SITE_ID = 1 AUTHENTICATION_BACKENDS= ... Read More
1K+ Views
In this article, we will see how to get the IP address of from where we get POST request. It is sometimes important to keep a check on the security parameters. Sometimes you might need to ban some IPs or you might need to check if anyone is sending too many requests from a single IP. Let's see how it can be done easily with a third-party package.ExampleCreate a Django project and an app. Setup urls and do some basic stuff like adding app in INSTALLED_APPS.We will not use any Django forms or models.First, install the django-ipware package −pip install ... Read More
1K+ Views
In this article, we will see how to use widgets in a Django form. Widgets can be quiet helpful to make the frontend better. Widgets are html elements that are rendered from Django form, textarea, input, password input, etc., all are widgets.First let's create a Django project and an app. I created the project with the name "tutorial14" and app with the name "djangoFormWidget".Add app in settings.py and include app's URL in project urls.py.Make every basic files and folders like Templates, home.html, forms.py.ExampleIn app's urls.py −from django.urls import path, include from . import views urlpatterns = [ path('', views.home, ... Read More
854 Views
In this article, we will see how to export model data in .csv format. Sometimes, you might need to export your model data in different formats such as .csv or json or .xlsx for further work or reporting. You can do this by making some sort of script but I have a better way to do that.Create a Django project and add 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 any html file.We only have work with settings.py, admin.py, models.py ... Read More
403 Views
While creating a Django website, sometimes you want a URL endpoint from where you can check your database, cache, and storage. In such cased, we can use a third-party package to keep a check on your system performance and other things and you can check your system even in production.In this article, we are going to make a URL endpoint which will give us system check.ExampleFirst of all, perform all the basic settings of apps and urls.Next, install the django-watchman package −pip install django-watchmanNow, in settings.py, add this −INSTALLED_APPS = ( ... 'watchman', )This will simply add watchman ... Read More
2K+ Views
If you ever worked with Django REST framework, then you surely know about JWT authentication. JWT authentication is used for token authentication and it is really a popular method for authentication in Django. JWT stand for JSON Web Token. Let's see how to work with it.First, install a package −pip install djangorestframework-simplejwt pip install djangorestframeworkWe are not going to need an App for this, we will just do a basic setup for Django REST framework frontend and authentication backend.ExampleIn settings.py, add the following −INSTALLED_APPS = [ ... 'rest_framework_simplejwt', 'rest_framework' ... ] REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ) }Here, ... Read More
792 Views
In this article, we are going to use a library in Django to see a brief report of database query count in terminal which can be used for debugging. It will provide a brief tabular report of every hit on any model object and print it on every hit, whether it is read or write. It will also calculate the response and request.ExampleDo some basic stuff like setting apps and urls.Install the django-querycount module −pip install django-querycountIn settings.py, add this −MIDDLEWARE += [ 'querycount.middleware.QueryCountMiddleware', ]This will enable the functionality of library and allow us to use it at runtime ... Read More
515 Views
In this article, we are going to make a project in which we will see how to make a Django table that will store all the data of hit count and detailed data of hit. It can be used generate useful reports. So, let's get started.Setup your urls.py and install the django-hitcount modulepip install django-hitcountExampleIn settings.py, add the following line −INSTALLED_APPS+ = ['hitcount']Here we added this library as an app in the project.Run the following commands −python manage.py makemigrations python manage.py migrateHere, we create migrations and then we migrate it.That's all. This library will create a table that will store ... Read More
1K+ Views
We usually make file or image related changes from the frontend. In this article, we will see how to make file management at Admin panel where we can manage different types of file that we are going to render from server to client.ExampleInstall the django-filer module −pip install django-filerIn settings.py, add the following −INSTALLED_APPS = [ ... 'easy_thumbnails', 'filer', 'mptt', ... ] THUMBNAIL_HIGH_RESOLUTION = True THUMBNAIL_PROCESSORS = ( 'easy_thumbnails.processors.colorspace', 'easy_thumbnails.processors.autocrop', #'easy_thumbnails.processors.scale_and_crop', 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 'easy_thumbnails.processors.filters', )Here, we have just added the necessary libraries as apps in our project. We added ... Read More