Django template for loop

Django template for loop
Django provides a template tag "for" to provide the for loop functionality in django templates. By using the for loop template tag we can iterate over lists, tuples, dict's just like we do in python programs.

Read more

django pass data from view to template

django pass data from view to template
As we know django is a MVC framework. So, we seperate business logic from presentational logic. We write business logic in views and we pass data to templates to present the data.

Read more

routers in Django Rest Framework

routers in Django Rest Framework
Routers are used with ViewSets in django rest framework to auto config the urls. Routers provides a simple, quick and consistent way of wiring ViewSet logic to a set of URLs. Router automatically maps the incoming request to proper viewset action based on the request method type(i.e GET, POST, etc). Let's start using routers. Working with DRF Route

Read more

django send email using mailgun api

django send email using mailgun api
We can send email in django using mailgun api. Mailgun is one of the trusted email service providers. When we send email using the mailgun it can directly deiver it to the recipient. As it is a trusted email service provider our email cannot be spammed. So, our information can be reached to the end user. By using mailgun we can send upto 10,000 ema

Read more

authentication in Django Rest Framework

authentication in Django Rest Framework
In previous articles we have developed an open API i.e any user (Authenticated and Un-authenticated) can access the API resource. If we want to want to know the information who is accessing the API then we have to autheticate the user. Authentication means the process or action of verifying the identity of a user. REST framework provides a number o

Read more

django admin custom form usage

django admin custom form usage
Django admin allows us to use custom form. In most of the cases we use default admin provided by django. But, in some cases we may need to use some validations on the model fields or we may want to skip some fields and update these fields while saving it. In this kinds of situations we can solve it by using the custom form in django admin. Let's do

Read more

how to add custom views to django admin

how to add custom views to django admin
how to add custom views to django admin without actually creating the database table ? Let's talk about it. In django admin to get the url link in the admin we have to register the model but in some cases we just need the a url with some functionality under an applicaiton. We can implement it with a simple trick. To implement it we have to create a

Read more

working with select_related in django

working with select_related in django
select_related is a queryset method in Django which returns new queryset result for a Django Model. select_related is more helpful in foreign-key relationships. It is useful when we are going to use those foreign-key relationship data later in our code. select_related is a preformance booster, which caches the result for the foreign-key relationshi

Read more

using custom widgets in django

using custom widgets in django
In Django we use built-in forms. After rendering the template with form and form fields we can see the equivalent html is generated from the form fields. How Django is doing that ? Well, to generate HTML from the form fields django uses form Widgets. In some cases we need the some specific HTML format from Django widgets. In such cases we write our

Read more

django static files usage

django static files usage
Every website needs to serve the extra files such as images, CSS, JavaScript. The name "static" itself indicates that contents of files do not change. So, in django to work with static files we need to make some configurations in setttings.py file.

Read more

how to use templates in django

how to use templates in django
Django is a webframework so, It needs to maintain the code in such a way that it should be easy to navigate and easy to read and maintain. As we already know the Django framework is a MVC, we do not write the HTML code in the views.py instead we write it in a template. In django web framework we generate dynamic HTTP response. While generating the

Read more

usage of group_by and string_agg in django, postgreSQL

usage of group_by and string_agg in django, postgreSQL
In this article we are going to learn how to optimize the queries in Django applications. Django has a built-in ORM which converts the django query into optimized SQL query. In some cases we need to group the data based on some common django field or a table column. This can also be done without using the group_by and string_agg in django query. In

Read more

Introduction to RESTful api's

Introduction to RESTful api's
REST(Representational state transfer) is a one of the architectural(designed with some specific rules and regulations) ways to transfer the data by using the HTTP protocol. In this article we will learn what are the restful api's and why we use it.we'll understand api request format and request methods in REST api's and it's usage. Why we use REST

Read more

getting started with django first app

getting started with django first app
Let's get started with our very first django application. I always recommend newbies to use the latest versions of django and python. Python2.X.X has no active support. We generally develop many projects on a single machine with different requirements(python packages). If we install python packages globally some ptojects may not work properly. To a

Read more

understanding the request-response lifecycle in Django

understanding the request-response lifecycle in Django
Let's start understanding the request-response lifecycle of a Django application. Every web application uses HTTP/HTTPS protocol. In the HTTP/HTTPS protocol client sends a request to the server based on the request data server sends the response back to the client. It's the basic principle of HTTP protocol. While setting up the django application i

Read more

django custom path converters

django custom path converters
In django version 2.0 introduced new way to write url patterns using "path". In django 2.0 regular expression type "url" is removed and added 2 things to work with urls. 1. using "path" and 2. using "re_path". For writing the clean urls django provided the path converters. It helps us to write clean and neat code and improves code readability. defa

Read more

django image and file upload using ajax

django image and file upload using ajax
Let's learn about how to work with Django image and file upload using Ajax. In most of the cases I personally use django file or image uploads using ajax. If we use normal upload then browser will reload the page in order to load the requested response and we will not have the files in the file fields due to page refreshed by the browser, again use

Read more

django html to pdf using pdfkit and wkhtmltopdf

django html to pdf using pdfkit and wkhtmltopdf
In many ecommerce django/python projects we sent invoices to the users in an email. We generally attach pdf documents to the email while sending the invoices to the user. Most of these invoices are pdf documents. Django is the most used python web framework of python programming language. In django, to generate invoice we generally uses html templa

Read more

understanding of HTTP protocol

understanding of HTTP protocol
Before talking about HTTP Protocol, let's talk about "Protocol". A protocol is a set rules to be followed to communicate with one another. Let's take two persons say A, B. Person A lives in USA and person B lives in India and he doesn't know english. Person A sent a message to B. Inorder to understand the message, B has to follow english language g

Read more

understanding Model View Controller(MVC) in Django

understanding Model View Controller(MVC) in Django
What is Model View Controller? We call it in short MVC. It's a software architecture pattern that is used to devide the complex software into simple parts based on the functionality. When we use Google for web search, we simply open Google and search for "food" let's say. Then google will show us results about food. This what we see. But, actually

Read more

understanding django project structure

understanding django project structure
In the previous article we have seen how to setup the django development environment. In this article we will learn about how to create django proect and django project structure. We care about project structure because it helps us to organise the complex project code. A well structured project will helps the developers to navigate through the code

Read more

deploy django app with apache server on ubuntu

deploy django app with apache server on ubuntu
In this article we will learn about how to deploy django app on apache server. Apache server is a free and open-source HTTP server that is free to use. It is a cross platform web-server, It support's most of the operating systems like windows, linux, Mac, etc. Apache server is not intended to use to create any website. The main purpose of apache is

Read more

setting up django development environment

setting up django development environment
Django Web Framework is becoming very popular because of its easyness to use and support for rapid development with good security and reliability. Django developers has a good demand in the industry. Before we are diving into django we need to install "python 3.x.x" in our OS(operating systems). Django is no longer providing the support for python

Read more

Introduction to django web framework

Introduction to django web framework
Django is a high level python web framework. It is a open source web framework released under the licence of BSD. Django allows developers to build web applications in a short span of time. Django applications are powerful, fast, most secure and exceedingly scalable. Django was designed to help developers to complete the web applications as quickly

Read more

using custom user model in django

using custom user model in django
When we start a new project we have to use custom user model in django application. Because, django provides basic fields required for the user. We may require to add extra fields in the future. So, we have to use custom user model. To implement the custom user model in django application we do not need to rewrite the model from the scratch. We ca

Read more

signup or sign-in using facebook to django application

signup or sign-in using facebook to django application
Nowadays most of the users are having the facebook account. Registration/Login will take the time fill the form and submit to create or login to our website. Adding the functionality to login/signup with facebook makes it very easy to login or to register to our website. There are many third party django packages are available to add facebook signu

Read more

Support Me on Patreon