Skip to main content

Command Palette

Search for a command to run...

How to setup django project with virtual environment

Updated
2 min read
How to setup django project with virtual environment
N

I am web developer and competitive programmer. I have a strong understanding of various programming languages and frameworks, including C++, PHP,HTML,CSS, and JavaScript.

What is Django?

Django is a robust web framework for Python that allows developers to build dynamic and robust web applications quickly. In this tutorial, we will review the steps to set up a Django project from scratch.

Before we start, make sure you have Python and pip (Python package manager) installed on your machine.

  • Install virtualenv using pip:

What is the virtual environment?

Virtual environments are used to isolate specific Python environments on a single machine, which is useful for managing dependencies for different projects. To create a virtual environment, run the following command:

pip install virtualenv
  • Now, create your project folder.
mkdir project
cd project
  • Create a virtual environment for your project:
virtualenv env

This will create a new directory called "env" within your project directory, which will contain the Python executable and all the packages you install for this project.

  • Activate the virtual environment:

    • for Powershell

        env\Scripts\activate.ps1
      
    • for Command Prompt

        env/Scripts/activate.bat
      
    • for Linux

        source env/Scripts/activate
      

You should see the name of your virtual environment in parentheses at the beginning of the command prompt, indicating that it is active.

(env) user@machine:~$
  • Install Django using pip:
pip install django
  • Create a new Django project:
django-admin startproject myproject

This will create a new Django project called "myproject" in the current directory.

  • Run the Django development server:

This will start the development server at http://127.0.0.1:8000/. You can access the Django administration site at http://127.0.0.1:8000/admin/.

cd myproject
python manage.py runserver

Congratulations! 🎉🎉 You have successfully set up a new Django project. From here, you can start building your web application and take advantage of the many features that Django provides.

I hope this tutorial has helped you get started with Django. If you have any questions or need further assistance, please don't hesitate to ask.

Django Tutorial

Part 1 of 6

In this Series you learn about Django and also we will create project of blog application in Django.

Up next

Creating App in Django

In this article, we will cover the basic steps for creating a simple app in Django.

More from this blog

N

Nilesh's Blog

8 posts