How best to understand the use of "project" in documentation

I’m brand new to Python & Django and a bit stumped by the use of the word “project”. When installing Django via the tutorial, I’ve read How to install Django on Windows and stumbled on py -m venv project-name. I suspect that what is meant there is different from the use of “project” in Writing your first Django app, part 1. The former seems more likely to be the name of an environment and the latter the name of a discrete website project. And I end not being clear on where (in which directory) commands should be entered. (Hope I’m not being to dense about all this!) I’d greatly appreciate clarification. Thanks.

Actually, their intent is that the “project-name” be the same in both cases - just in different parent directories.

Yes, one is the name of the project you are working on, and that same name can be used as the name for your virtual environment. Their perspective is that you will create a separate venv for each project. Using the same name makes it easy to remember which venv is used by which project.

As far as what directories each of those should reside in, it’s really up to you. I have a directory named “ve” that contains all my venvs, and one named “git” to hold all my git repos. But the choices are yours.

1 Like

I like to name the environment .venv inside of the project directory, but @KenWhitesell’s method is great, too.

django-admin and manage.py

So there are two Django-specific commands that may be confusing here as well:

  1. django-admin
  2. manage.py

These are very similar. The main differences are:

  • manage.py doesn’t exist until you run the command django-admin startproject project_name [directory]
  • manage.py loads your settings file into an environment variable called DJANGO_SETTINGS_MODULE

You can read more about the two utilities in the docs.

These utilities have two commands that highly depend on where you’re at in your terminal or command line prompt because they create files for you:

  1. startproject
  2. startapp

If you click those links, it will take you to the Django documentation on these commands which explains that you can optionally specify the directory where you want the template files to be created.

Example

When I start a new project, I like to create the folder in my filesystem first. Then I cd into it, start a Python virtual environment, install Django, and run startproject. So something like the following…

cd C:\Users\Lance\Programming\Projects
mkdir Polls
cd .\Polls\
python3.11 -m venv .venv  # creates my virtual environment
.\venv\Scripts\Activate.ps1  # this activates the venv in Powershell
python -m pip install django
django-admin startproject polls_project .  # note the "dot" at the end to specify directory
python manage.py startapp statistics  # when ready for a Django app

This puts my virtual environment at the base of this project folder alongside the manage.py file and the base project directory.

Hope that helps! I think you’ll like it once you know the lay of the land!

1 Like

Lance - this is most helpful. The best part is it puts in one place a number of concepts appearing in separate doc pages. Many thanks.

1 Like

That was very nice, thank you @truckee!

Thank you so much, Sir Lance, this is really helpful. The initial step is already difficult for me but after endless searching, I found this and it worked. Thx again.

1 Like