Search Here

How to Install Django | Start Project, Create App and Run Project

How to Install Django | Start Project, Create App and Run Project

The Django is a powerful web framework for those who want to build web applications using the python programming language.
Django comes with an admin dashboard out of the box, ORM (Object Relationship Mapping) which is a very powerful tool while working with databases, security features such as SecurityMiddleware, CsrfViewMiddleware, AuthenticationMiddleware, clickjacking, etc.

Django has proved itself as a well-known framework for web development as it is used by companies such as.

  • Instagram: which is a social media platform.
  • Disqus: which provides blog commenting services to websites.
  • Spotify: which provides media and audio streaming services.

the above are some of the companies that use the Django framework as part of their technology stack.

Why should you learn Django

The Django Framework is not the only web development framework that uses python but it has its own advantages such as :

  • Rapid Development
  • Admin Dashboard that comes with Django by default.
  • A Strong Security system that protects from Cross-site request forgery attacks.
  • ORM for mapping complex relationships. it also provides reverse relationship mapping.
  • Django ORM’s are lazy which means they do not fetch data from database useless they are evaluated this helps developers write better efficient code.

Now we have a lot of reasons to learn Django so let us get started.

Table of Contents

Prerequisite

The Django framework is a Python Framework and to work without the hassle you must first have a better understanding of how python code gets executed.
If you want to learn Python then click on this link.

Install Django

To install Django you first need to install pip which is kind of a package manager for python. To install pip go to this link

After successfully installing pip open terminal and type.

pip install Django 

You need to install virtual env for containing separate python version

pip install virtualenv

Start a new Project

Go to the directory to create your first project. I have created a directory in my Desktop/Python in this directory I’ll create a Django project.

~Desktop/Python>$ django-admin startproject test_django

You can see startproject created a new project named test_django.

Create a new App

Navigate inside the project and to create an app we’ll type

~Desktop/Python/test_django>$ django-admin startapp my_site

Your app my_site gets created now you need to register this to settings.py in path=test_django/settings.py.

INSTALLED_APPS = [
    ....
    'django.contrib.staticfiles',
    'my_site.apps.MySiteConfig', # add this path to your app 
]

Running project

Navigate to the root of your project test_django and run the project type.

~Desktop/Python/test_django>$ python manage.py runserver

You’ll see this message on the terminal.

Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

August 24, 2020 - 05:24:00
Django version 2.1, using settings 'test_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Ignore the migration warning and go to URL http://127.0.0.1:8000/.

Final Output - How to Install Django | Start Project, Create App and Run Project

Final Output – How to Install Django | Start Project, Create App and Run Project

If you see the above output that you have successfully installed Django.

Conclusion

We have come to the final part of our post “How to Install Django Framework and Start and Run Project”.

Summary
Review Date
Reviewed Item
How to Install Django | Start Project, Create App and Run Project
Author Rating
51star1star1star1star1star
Software Name
Django Framework
Software Name
Windows Os, Mac Os, Ubuntu Os
Software Category
Web Development