Creating My First Django Application Part 1

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.
Ridiculously fast.
Django was designed to help developers take applications from concept to completion as quickly as possible.
Reassuringly secure.
Django takes security seriously and helps developers avoid many common security mistakes.
Exceedingly scalable.
Some of the busiest sites on the Web leverage Django’s ability to quickly and flexibly scale.
How to get Django ?
Django is available open-source under the BSD license. We recommend using the latest version of Python 3. The last version to support Python 2.7 is Django 1.11 LTS
Since Python is a platform-independent language, Django has one package that works everywhere regardless of your operating system.You can download the latest version of Django from the link
http://www.djangoproject.com/download
Option 1 : Get the latest official version
pip install Django==3.0.3
Option 2 : Get the latest development version
The latest and greatest Django version is the one that’s in Git repository
git clone https://github.com/django/django.git
You can also download a gzipped tarball of the development version. This archive is updated every time developer commit code.
Installing Django from source code
- Extract the source code from the downloaded gzipped tarball
- Open the terminal and change directory to the django source code folder and then run
python setup.py install
3. Check the installation
python -c “import django; print(django.get_version())"
Database Setup
Django supports several major database engines and you can set up any of them based on your comfort.
- MySQL (http://www.mysql.com/)
- PostgreSQL (http://www.postgresql.org/)
- SQLite 3 (http://www.sqlite.org/)
- Oracle (http://www.oracle.com/)
- MongoDb (https://django-mongodb-engine.readthedocs.org)
- GoogleAppEngine Datastore (https://cloud.google.com/appengine/articles/django-nonrel)
Creating project
To create a project open terminal and run the following command
django-admin startproject “myproject”
The above command will create a folder in the directory with following structure

Project Structure
The “myproject” folder is just your project container, it actually contains two elements −
- manage.py — This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db…). To get a full list of command accessible via manage.py you can use the code −
- myproject subfolder — This folder is the actual python package of your project. It contains four files i.e __init__.py, settings.py, urls.py, wsgi.py
To see the available commands of manage.py run following command
python manage.py help

To run a command use
python manage.py runserver
Creating an Application
To create a application in a project , use
python manage.py startapp myapp
The above command will create a folder named “myapp” with application structure

Application Structure
The “myapp” folder is just your application folder , it actually contains following elements −
- __init__.py — Just to make sure python handles this folder as a package, because of this you can import your application and its sub modules to the other part of application / project
- admin.py — This file helps you make the app modifiable in the admin interface. admin.py file are use to display your models in django admin panel also you can customize your admin panel using admin.py file.
- models.py — This is where all the application models are stored. A model is a class that represents table or collection in our DB, and where every attribute of the class is a field of the table or collection. Models are defined in the app/models.py
- tests.py — This is where your unit tests are. Tests are simple routines that check the operation of your code.
- views.py — This is where your application views are. A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image, etc.
To know more visit https://www.djangoproject.com/
Move to Next Part Creating My First Django Application Part 2
References
- https://docs.djangoproject.com
- https://tutorialspoint.com/
- Django Unleashed — Book by Andrew Pinkham