Unclear about folder structure with virtual environment

Hi! Welcome to the world of Django.

So probably the reason you won’t find any definitive answers on this topic is because there aren’t any.

There’s no one right-way to set up your environment, just different practices based on need.

Keep in mind:

  • Python virtual environments exist to allow you to keep separate groups of libraries for different “projects” or groups of projects. The virtual environment itself is not a part of your Django project, it is effectively a container (generic term, not in the “docker” sense) for the libraries that your Django project will use.

    • Some people will put their virtual environment within their projects because they have separate virtual environments for each Django system they build.

    • Some people put their virtual environments in other locations. In my case it’s because I typically end up building multiple projects based on the same virtual environment - I want to ensure everything remains consistent between projects.

  • In essence, your Django code runs “inside” the virtual environment, not the reverse. (The Python runtime environment runs Django, and then Django runs your code.)

(By the way, this is actually a fairly common question that gets asked. There have been a couple of discussions on this topic here. See Correct practice for importing third party modules as one.)

As a side note, the basics of deployment and project organization have not changed between Django v3 and v4. Without looking at those tutorials in detail, I’m willing to guess that there probably aren’t any material differences that would prevent you from learning.

1 Like