Wednesday, December 18, 2019

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.

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...