Python Django

Django Class Based View Vs Function Based View

The Django view function is responsible to process user request and return a django.http.HttpResponse object to client browser. And view function is defined in Django app views.py file. But besides this, you can also define custom view class to achieve same purpose. Your view class should extends Django provided built-in class-based generic views such as …

Django Class Based View Vs Function Based View Read More »

How To Enable Or Disable CSRF Validation In Django Web Application

Django has provide a feature that can help you to avoid csrf attack on your Django application. But some times especially in your development environment, you do not want this feature when send post request to your web server use curl in command line, if this feature enabled, you will get errors. This article will …

How To Enable Or Disable CSRF Validation In Django Web Application Read More »

How To Return Html File As Django View Response

Morden web application are all designed with MVC( Model, View, Controller ) pattern. But in django, the pattern name is MTV( Model, Template, View Function ). So in django, template html is the view, and view function plays the role of controller. This article will tell you how to create template and view function in …

How To Return Html File As Django View Response Read More »

How To Create Django View Template Files Structure Correctly Use Block & Include Tag

We use template html files in Django web application to render model data. And Django provide a very clear and easy way for you to manage the combination of layout page and content page. So you can define layout page in one template html file, and then define content page in another template html file. …

How To Create Django View Template Files Structure Correctly Use Block & Include Tag Read More »

How To Assign Variables To Child Template Use {% include %} Tag In Django

We have learnt how to add search result pagination in the user list page in article Django Filter And Pagination Example. In that example, we use below html code in DjangoHelloWorld / templates / dept_emp / user_list.html template file to add pagination. But how to add pagination to other list page such as dept_list.html and …

How To Assign Variables To Child Template Use {% include %} Tag In Django Read More »

How To Use Django url Tag And reverse() Function To Avoid Url Hard Coded

Hard coded url in your Django template html files or views.py file is a bad practice. Because it is difficult to maintain url changes. If you change one url, you may need to change that url in a lot of pages. So Django provide template url tag and reverse function for you to avoid hard …

How To Use Django url Tag And reverse() Function To Avoid Url Hard Coded Read More »