DEV Community

loading...
Cover image for Getting Started with Django (Part 1)

Getting Started with Django (Part 1)

aakas profile image aakas Updated on ・2 min read

Django is a free and open-source high-level Python web framework. As Django itself claims as “The web framework for perfectionists with deadlines.” is absolutely right. I have been using Django for around 1 and a half years, and I find it very useful in web development.

How to get started with Django?

First of all, the prerequisite to get started with django is one must know programming and Python programming language. It will be very useful if one has done some project on the python programming language. The next thing, it is good to know about the database, HTTP methods, Html / CSS.

If you have the above-mentioned knowledge then it will be quite easy to understand web development and using django for web development.

Now let’s do some work.

To install django in your local machine we use “ pip ”. If you are using a Linux OS then “ pip3 “ is used to install any python packages. pip3 means use the package installer for python3. And if you are in windows, then only “pip” will be enough.

Before installing django on local machine, I highly recommend installing python package named virtualenv. “ virtualenv “ creates a separate virtual environment for the project and saves from the trouble of package version difference errors. Just install virtualenv with pip install virtualenv

  1. Create a virtual environment for the project. Here “ venv ” means the name of a virtual environment. One can use any name. Also activate the virtual environment.
    virtualenv venv

    cd venv/scripts/

    activate
Enter fullscreen mode Exit fullscreen mode
  1. Install django in the activated virtual environment
    pip install django
Enter fullscreen mode Exit fullscreen mode
  1. Now just type these commands. And you will have your first django project run successfully
    cd ../..

    django-admin startproject projectname .

    python manage.py startapp core

    python manage.py makemigrations

    python manage.py migrate

    python manage.py createsuperuser

    python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Here cd../... is used to change the directory to move backward on the file system.

django-admin is the command-line utility command to startproject named projectname. And projectname could be any of your choices.

python manage.py startapp core command is to use python as an interpreter for manage.py and startapp named core. Similarly, the app name could be any of your choices.

Then makemigrations command makes a script to perform on the database.
migrate command executes the script made by makemigrations command.

You could also create a superuser using createsuperuser command to access the admin section of the website.

And finally, the runserver command runs the local server built-in django. After that enter http://localhost:8000/ and you can see your website running perfectly.

Discussion (0)

Forem Open with the Forem app