Upadesh Shrestha

  •  ·  Administrator
  • 997 views
Friends
Empty
Relationships
Empty

Creating a virtual environment and installing Django is a great way to manage your project dependencies. Here are the steps to do it:

1. Create a Virtual Environment

Navigate to Your Project Directory: Open your terminal or command prompt and navigate to the directory where you want to create your project:

cd /path/to/your/project

Create the Virtual Environment: Use the venv module to create a virtual environment. Replace venv with your desired environment name:

python -m venv venv

Activate the Virtual Environment:

  • On Windows:
.\venv\Scripts\activate
  • On macOS and Linux:
source venv/bin/activate

After activation, your terminal prompt should change to indicate that you are now working within the virtual environment.

2. Install Django

Install Django Using pip: With the virtual environment activated, install Django using pip:

pip install django

Verify the Installation: You can verify that Django is installed by checking its version:

django-admin --version

3. Create a Django Project

Create a New Django Project: Use the django-admin command to create a new project. Replace myproject with your desired project name:

django-admin startproject myproject

Navigate to the Project Directory: Change into the project directory:

cd myproject

Run the Development Server: Start the Django development server to ensure everything is set up correctly:

python manage.py runserver

Open your web browser and go to http://127.0.0.1:8000/ to see the Django welcome page.

That's it! You've successfully created a virtual environment, installed Django, and started a new Django project. If you have any questions or run into issues, feel free to ask!