Artificial Intelligence Design Digital Innovation Machine Learning Software Startups Tech/Gadgets Technology

Building And Implementing A Blog App Using Django: Adding Forms

Pinterest LinkedIn Tumblr

Table of Contents

Introduction

In previous articles, we have learnt about Django, how it works and how we can use it in conjunction with Python to build several apps like a two paged web application, a message board app and a blog app. In the previous article, we learnt and saw steps on how to create and implement a blog app. This article is a continuation of the previous one as in this article, we shall further extend the features of our blog app by adding the creation of forms where users can create, edit and delete any of their blog entries. The question, therein is “What Are Forms?”.

Forms

Forms are structured documents used to collect information in a logical and meaningful fashion for communication and for passage to another entity. Forms are very common but very complicated to implement correctly. When accepting user input, proper error handling is required, there are also several security concerns (XSS Attacks) and UI considerations around how to alert the user to problems with the form, not to mention the need for redirects on success.

Fortunately, Django provides an easy and effective way to go about this. The Django’s built-in Forms abstract away much of the difficulty and provides a rich set of tools to handle common use cases while working with forms.

The first step is to open up our blog app directory in our visual studio code, then open the “base.html” file in the templates folder. There, we will update our base template to display a link to a page for entering our new blog posts by adding the following:

ALSO READ  The Truth About AI Getting "Creative"

<a href= “{% url ‘post_new’ %}”></a>

where “post_new” is the name for our URL.