Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Ath Tripathi
Page 3 of 8
How to make any Django model's file downloadable?
You can use the django-downloadview package to make any file in your Django model downloadable. This package provides a simple way to serve files while handling security and performance considerations. In this article, we will see how to make a file downloadable in our Django project using django-downloadview. Installation First, install the package using pip: pip install django-downloadview Now create a Django project and an app. Set up urls and add the app in INSTALLED_APPS. Also set up MEDIA_ROOT and MEDIA_URL in settings.py. Creating the Model In models.py, create a model ...
Read MoreHow to implement django-material in your Django project?
Django-material is a library that applies Google's Material Design styling to Django forms without requiring external CDNs. It automatically transforms your standard Django form widgets into beautiful, Material Design-styled components. Installation First, install the django-material package using pip ? pip install django-material Configuration Add 'material' to your INSTALLED_APPS in settings.py ? INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'material', # ...
Read MoreDjango – Handling multiple forms in single view
In Django web development, you often need to handle multiple forms within a single view. This article demonstrates how to create a function that manages two forms simultaneously using Django's MultiModelFormView. Project Setup Create a Django project and app. For this example, we'll use "multipleFormHandle" as the project name and "formhandlingapp" as the app name. Complete the basic setup by including the app in settings.py INSTALLED_APPS and adding the app's URL to the project's main URL configuration. Create forms.py in the app directory and a "templates" folder containing home.html. Install the required library ? ...
Read MoreGoogle Authentication in Django
Google Authentication allows users to log into your Django application using their Google accounts. This article demonstrates how to implement Google social authentication using Django Allauth library. Setting Up Google OAuth Credentials First, configure Google OAuth credentials in Google Cloud Console ? Go to Google Cloud Console and create a project. Navigate to OAuth consent screen and create a consent screen. Go to Credentials and click "Create Credentials" → "OAuth client ID". Select "Web application" and add these URLs: http://127.0.0.1:8000/ http://127.0.0.1:8000/accounts/google/login/callback/ Save the generated Client ID and Client Secret for later ...
Read MoreEnabling GitHub OAuth in Django
Django allows integration with GitHub OAuth for user authentication, making it easy for users to log in using their GitHub credentials. This tutorial demonstrates how to implement GitHub OAuth in a Django application using the django-allauth library. Setting Up GitHub OAuth Application First, create a GitHub OAuth application: Go to GitHub Developer Settings Create a new OAuth App with these URLs: Homepage URL: http://127.0.0.1:8000/ Authorization callback URL: http://127.0.0.1:8000/accounts/github/login/callback/ Save the Client ID and Client Secret ...
Read MoreExporting models data in Django
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, json, or .xlsx for further work or reporting. Django provides an elegant solution using the django-import-export package. We will create a Django project with a simple model and configure it to enable data export functionality through the Django admin interface. Installation and Setup First, install the required package − pip install django-import-export Add the library to your project's INSTALLED_APPS in settings.py − ...
Read MoreDjango runtime system check
When creating a Django website, you sometimes need a URL endpoint to monitor your database, cache, and storage systems. The django-watchman package provides runtime system checks that help you monitor your application's health in both development and production environments. In this article, we'll create a URL endpoint that provides comprehensive system health checks for your Django application. Installation First, install the django-watchman package using pip ? pip install django-watchman Configuration Adding to INSTALLED_APPS In your settings.py file, add watchman to your installed apps ? INSTALLED_APPS = [ ...
Read MoreDjango rest-framework JWT authentication
Django REST Framework JWT authentication provides a secure token-based authentication system using JSON Web Tokens. JWT tokens contain encoded user information and are ideal for stateless authentication in API applications. Installation First, install the required packages ? pip install djangorestframework-simplejwt pip install djangorestframework Configuration Settings Configuration In settings.py, add the following configuration ? INSTALLED_APPS = [ # ... other apps 'rest_framework', 'rest_framework_simplejwt', # ... other apps ] REST_FRAMEWORK = { ...
Read MoreDjango query count in terminal for debugging
In this article, we'll use the django-querycount library to monitor database queries in Django applications. This debugging tool displays a detailed report of database query counts in the terminal, helping developers identify performance bottlenecks by tracking every database hit on model objects. Installation First, install the django-querycount package using pip ? pip install django-querycount Configuration Add the QueryCountMiddleware to your Django project's middleware in settings.py ? MIDDLEWARE += [ 'querycount.middleware.QueryCountMiddleware', ] This middleware will automatically monitor all database queries when DEBUG = True in your ...
Read MoreDjango model object hit counting
In this article, we will create a Django project that tracks and stores hit count data for model objects. This functionality helps generate useful analytics reports by monitoring page views and user interactions. Installation and Setup First, install the django-hitcount module using pip ? pip install django-hitcount In your settings.py file, add the hitcount app to your installed apps ? INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', ...
Read More