What is Django?
Django not only used for making websites, rather than it is used for creating web applications. Django can be used to create dynamic high-security web applications.
Django is an open source web application framework, written in Python. A web framework that is a set of components that helps to develop websites faster and easier.
For authentication, one of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface.
Django Design Principles:
- Less Coding: Less code so in turn a quick development.
- Don’t Repeat Yourself (DRY): everything should be developed only in exactly one place instead of repeating it again and again.
- Fast Development: Django’s philosophy is to do all it can to facilitate hyper-fast development.
- Clean Design: Django strictly maintains a clean design principle. throughout its own code and makes it easy to follow best web-development practices.
- Loosely Coupled: Django aims to make each element of its stack independent of the others.
How to start Django Project:
Step 1: django-admin startproject mysite
Step 2: python manage.py startapp webapp
Step 3: To create the first view,
Open the file webapp/views.py
We import the class HttpResponse from the django.http module to render to the specific html pages.
The view returns an HttpResponse object that contains the generated response. Each view function is responsible for returning an HttpResponse object.
Step 4: In the next step to specify the root, URLconf at the webapp/urls.py path,
we need to write:
We have specified the paths for admin, index and home.
Step 5: To run the app, we have to write:
$ Python manage.py runserver
Step 6: For migration, to create the tables in the database, we need to write the command:
$ Python manage.py migrate
Step 7: To create the models we will write:
here we have created models for Question, Choice and Board.
Finally the output is: