Getting started with Django

 



  • Back-end web framework.
  • Free, open source and written in Python.
  • It makes it easier to build web pages using Python.
  • Follows the MVT design pattern
  • The data is delivered as an Object Relational Mapping (ORM)


Django serves pages in what way?

  • When the client sends a request to the server, it checks the "urls.py" file for the right match and calls the view that matches the URL.
  • The views are written inside the "views.py" file, which checks for the respective models within the "models.py" file.
  • The view sends the data from the model to the corresponding template file (which contains HTML and Django tags) and serves the template to the client.

Create a virtual environment
Before creating a project and working on it, it's better to create a virtual environment for it. Because there are many libraries, you may want to include them in your project since they don't need to be installed globally. You can create a virtual environment in this way.

Note*: Activate your virtual environment before continuing with the following steps.

Install Django
You can install Django by providing the below command in the terminal.
# pip install Django

Check the installed version of Django.
# django-admin --version

Create and Run a Project
To create a project, you can use the django-admin command.
django-admin startproject project_name
If you don't want to create a new project folder with the name of your project, you can do like this way
# django-admin startproject myproject .

To run this project
# cd project_name
# python manage.py runserver

Then go to this URL in your browser. 127.0.0.1:8000


Create an Application 
To create an application you can use the 'startapp' command with the application name.
# python manage.py startapp myapp


Migrations
Django uses migrations to propagate model changes you make into your database schema.
# python manage.py makemigrations
# python manage.py migrate


Django admin panel
To access the Django default admin panel you need to create a super user account.
# python manage.py createsuperuser
Now you can access the admin panel using this URL.

Comments

Popular Posts