Creating My First Django Application Part 1

Ridiculously fast.

Reassuringly secure.

Exceedingly scalable.

How to get Django ?

Option 1 : Get the latest official version

pip install Django==3.0.3

Option 2 : Get the latest development version

git clone https://github.com/django/django.git

Installing Django from source code

  1. Extract the source code from the downloaded gzipped tarball
  2. Open the terminal and change directory to the django source code folder and then run
python setup.py install
python -c “import django; print(django.get_version())"

Database Setup

  1. MySQL (http://www.mysql.com/)
  2. PostgreSQL (http://www.postgresql.org/)
  3. SQLite 3 (http://www.sqlite.org/)
  4. Oracle (http://www.oracle.com/)
  5. MongoDb (https://django-mongodb-engine.readthedocs.org)
  6. GoogleAppEngine Datastore (https://cloud.google.com/appengine/articles/django-nonrel)

Creating project

django-admin startproject “myproject”
Structure of a Project

Project Structure

  • 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
python manage.py help
Available list of commands manage.py
python manage.py runserver

Creating an Application

python manage.py startapp myapp
Structure of an Application

Application Structure

  • __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.
  1. https://docs.djangoproject.com
  2. https://tutorialspoint.com/
  3. Django Unleashed — Book by Andrew Pinkham

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store