Found 26504 Articles for Server Side Programming

Django – Making a contact form and storing its data without model, query and html

Ath Tripathi
Updated on 26-Aug-2021 12:15:56

982 Views

In Django, you can create a contact form very easily but it takes managing a lot of things like making forms, views, models, and then register the model in Admin, etc. In this article, we will see how to use a predefined package for our contact form which will save the data in a predefined model.We will make a contact form which will store data in model without writing any code in models.py or views.py or writing any html. So, let's get started.ExampleFirst, create a Django project and an App.Install the django-contactforms package −pip install django-contactformsThen, in settings.py, add the ... Read More

Importing data into models in Django

Ath Tripathi
Updated on 26-Aug-2021 12:11:25

4K+ Views

In this article, we are going to see how to import data from json format to model. We can import data from json, csv, xlsx, yml, etc. to model.First of all, create a Django project and an app. Set up urls and do some basic stuff like adding the 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 to work with settings.py, admin.py, models.py and admin urlpoint.ExampleInstall the django-import-export package −pip install django-import-exportIn settings.py, add the following line −INSTALLED_APPS += ['import_export']It will add import_export as an app ... Read More

Implementing models reversion in Django

Ath Tripathi
Updated on 26-Aug-2021 12:09:03

921 Views

In this article, we are going to learn how to add object's data tracking, deleted data recovery and recovery in objects. Reversion means getting back your deleted model data, it will recover all of your deleted data in a single click and it even gives tracking of each model object.First create a Django project and an app and add app inINSTALLED_APPS in settings.py.Setup your urls.py and install the django-reversion module −pip install django-reversionIn settings.py, add the following line −INSTALLED_APPS = ['reversion']ExampleI will not go to views.py and urls.py because they are not important for this task.Now in models.py, add the ... Read More

How to make any Django model's file downloadable?

Ath Tripathi
Updated on 26-Aug-2021 12:06:43

1K+ Views

You can use the django-downloadview package to make any file that you have in your project downloadable. You can host the files on a server.In this article, we will see how to make a file downloadable in our Django project. It will be a fun topic and you will love it.First, install the package −pip install django-downloadviewNow create a Django project and an app. Set up urls and do some basic stuff like adding app in INSTALLED_APPS. Also set up MEDIA_ROOT and MEDIA_URL in settings.py.ExampleIn models.py, add the following lines −from django.db import models # Create your models here. ... Read More

How to implement django-material in your Django project?

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

2K+ Views

Material Design is a design template that is very popular among developers. It is used at the frontend as CDN. In this article, we are going to see how to use material design on our form widgets and render that form from our views.Django-material is a library that will apply material design to rendered html file or form widget without CDN.First, install the django-material package.pip install django-materialSetup project and app and urls.In settings.py −INSTALLED_APPS+=['material']My app name is "myapp".ExampleIn models.py −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)Here, we created a ... Read More

Django – Handling multiple forms in single view

Ath Tripathi
Updated on 26-Aug-2021 11:53:23

6K+ Views

We sometimes need to handle multiple forms in a single function or view. In this article, we will see how to write a function which will handle two forms at the same time and in same view. It is handy in many cases; we will handle more than two forms too.Create a Django project and an app, I named the project "multipleFormHandle" and the app as "formhandlingapp".Do some basic stuff like including app in settings.py INSTALLED_APPS and include app's url in project's url.Now create forms.py in app and a "templates" folder in the app directory. Add home.html in templates.Install the ... Read More

Google Authentication in Django

Ath Tripathi
Updated on 26-Aug-2021 12:01:15

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

Enabling GitHub OAuth in Django

Ath Tripathi
Updated on 26-Aug-2021 11:39:17

733 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

Getting POST request IP address in Django

Ath Tripathi
Updated on 25-Aug-2021 13:21:39

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

Form widget in Django

Ath Tripathi
Updated on 25-Aug-2021 13:19:32

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

Advertisements