Skip to main content

Python Django: Basic Introduction

What is Django ?

Django is web framework written in python for rapid development of data-driven webapp. The primary goal and principle of django is DRY("don't repeat yourself").
Django is a much heavier weight web framework than Flask with a lot more out-of-the-box features so you can focus on writing your app without needing to reinvent the wheel. By default, django prevents most common security mistakes like XSS, CSRF, SQL injection etc. Django is a framework for perfectionists with deadlines.
*Create Django Project

  • python (python3 is recommended)
  • django ( at least version 2.0 or higher)
  • text editor (atom is recommended because its works almost same on different operating system)
Django divides all of its web applications into projects, composed of different parts.

To create and start a new project, run the command in terminal.
  • django-admin startproject projectname
where projectname is the name of your project.

Django is built on the idea of packages. A web application can be made of multiple packages, each  serving a slightly different purpose, and Django will help manage these.
Project Components
  • Django creates a number of files within projectname directory
    • : defines the directory projectname as a Python package, collection of multiple Python files.
    • : basic settings, like time zone, other applicationinstalled in the project, what sort of database is used, etc.
    • determine what URLs/route can be accessed when using the web application.
    • a file that helps to deploy an application to a web server.
  • a Python script that can be used to perform useful operations on web application.
  • Django project consist of one or more Django applications, or apps, which serves a particular purpose.
Create A Basic Application:
To create an app, inside the project directory, run the following command.
  • python3 startapp appname
where appname is the name of your application. This command create a directory appname inside of .
project directory. This directory contains the number of files automatically.
Inside appname directory
  • It contains the code that determines what the user sees at a particular route or url.
  • contains the configurations for app.
  • For admin related task in the app.
  • It contains the code for testing app whenever new feature is added on app
  • Its conatins the models that create the database.

In the above image of text editor, article is project name and inside article demo is my app name.

Running Web Server

run the following command in project directory.
  • python3 runserver
now server is start on your localhost. Follow link in your browser to see default page.

Popular posts from this blog

Introduction to Java Security

Introduction to Java Security The Java security architecture includes a large set of application programming interfaces (APIs), tools, and implementations of commonly-used security algorithms, mechanisms, and protocols. The Java security APIs span a wide range of areas. Cryptographic and public key infrastructure (PKI) interfaces provide the underlying basis for developing secure applications. Interfaces for performing authentication and access control enable applications to guard against unauthorized access to protected resources. The JDK includes a number of providers that implement a core set of security services. It also allows for additional custom providers to be installed. This enables developers to extend the platform with new security mechanisms. The JDK is divided into modules. Modules that contain security APIs include the following:

Module Description java.base Defines the foundational APIs of Java SE;  contained packages include,  and…

SQL Injection

Overview A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system. SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands. Threat ModelingSQL injection attacks allow attackers to spoof identity, tamper with existing data, cause repudiation issues such as voiding transactions or changing balances, allow the complete disclosure of all data on the system, destroy the data or make it otherwise unavailable, and become administrators of the database server.SQL Injection is ve…

Insertion Node in the Linkelist.

In this post, methods to insert a new node in linked list are discussed. A node can be added in three ways
1) At the front of the linked list
2) After a given node.
3) At the end of the linked list
public class Linkedlist { Node head; class Node{ int data; Node next; Node(int d){ data =d; next=null; } } // INSERT THE NODE AT THE BEGIN OF LINKEDLIST. public void insertAtfront(int new_data){ // Node temp = head; Node new_node = new Node(new_data); = head; head = new_node; }  // INSERT THE NODE AT THE GIVEN POSITION IN LINKEDLIST.
public void insertAtGiven(Node prev_node,int new_data) { if(prev_node == null){ System.out.print("previous node can't be null"); return; } Node new_node = new Node(new_data); =; = new_node; } // INSERT THE NODE  AT THE END OF THE LINKEDLIST.   public void insertAtEnd(int new_data){ Node new_node = new Node(new_data); new_node.nex…