Monday, April 21, 2025

How to Create Virtual Environment and Django Project

C:\Users\user>python -m venv DJANGO_PROJECT

C:\Users\user>cd DJANGO_PROJECT

C:\Users\user\DJANGO_PROJECT>cd Scripts

C:\Users\user\DJANGO_PROJECT\Scripts>activate

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts>

We have created a new virtual environment named "DJANGO_PROJECT" using the venv module.

Then we navigated to the virtual environment's Scripts directory and activated the environment using the activate command. The (DJANGO_PROJECT) prefix in the command prompt indicates that the virtual environment is currently active.

Any Python packages installed while the virtual environment is active will be isolated from the global Python environment and will only be available within the virtual environment. 

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts>pip install django
Collecting django
  Using cached https://files.pythonhosted.org/packages/..../Django-3.0.7-py3-none-any.whl
Collecting pytz (from django)
  Using cached https://files.pythonhosted.org/packages/..../pytz-2020.1-py2.py3-none-any.whl
Collecting sqlparse>=0.2.2 (from django)
  Using cached https://files.pythonhosted.org/packages/..../sqlparse-0.3.1-py2.py3-none-any.whl
Collecting asgiref~=3.2 (from django)
  Using cached https://files.pythonhosted.org/packages/..../asgiref-3.2.10-py3-none-any.whl
Installing collected packages: pytz, sqlparse, asgiref, django
Successfully installed asgiref-3.2.10 django-3.0.7 pytz-2020.1 sqlparse-0.3.1
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts>

The command pip install django installs the Django package in the virtual environment. The output shows that the package and its dependencies (pytz, sqlparse, and asgiref) were successfully installed. 

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts>django-admin startproject DJANGO_PROJECT

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts>cd DJANGO_PROJECT

(DJANGO_PROJECT) C:\Users\user\DJANGO_PROJECT\Scripts\DJANGO_PROJECT>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 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.
June 21, 2020 - 21:59:50
Django version 3.0.7, using settings 'DJANGO_PROJECT.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[21/Jun/2020 22:00:09] "GET / HTTP/1.1" 200 16351
[21/Jun/2020 22:00:09] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[21/Jun/2020 22:00:09] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[21/Jun/2020 22:00:09] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[21/Jun/2020 22:00:09] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
Not Found: /favicon.ico
[21/Jun/2020 22:00:09] "GET /favicon.ico HTTP/1.1" 404 1980

This code creates a new Django project called "DJANGO_PROJECT" and runs the development server.

  • django-admin startproject DJANGO_PROJECT creates a new Django project in a new directory called "DJANGO_PROJECT".
  • cd DJANGO_PROJECT navigates to the newly created directory.
  • python manage.py runserver starts the development server on the default port 8000 and displays some information in the console about the server status, including the version of Django being used and the settings file being used. It also warns that there are 17 unapplied migrations that should be run, and provides instructions on how to run them. The server then listens for incoming HTTP requests and logs information about each request it receives.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...