Creating a project in Django - 02

With the virtual environment already configured:

Creating a virtual environment in Django/Python with venv 1

In theory, if we open the terminal here, it should usually activate it automatically, which I think is what happened. A simple way to know if this is active or not, for example, there are times when the virtual environment is placed here in parentheses:

(env)

But in this case it is not showing it, that also happens but we can place a:

$ pip freeze

And see if it does not return anything it means that it is active in this case because it is a completely clean virtual environment you can also write here cd any or your terminal you write

$ pip freeze

And in this case it should return one but it would be the virtualenv which is installed globally but I don't know what happened here we can also try to activate the virtual environment here; the next thing we are going to do is install Django with:

$ pip install Django

We put here again a pip freeze we don't have anything perfect we are going to install Django you can also pass a specific version:

$ pip install Django==5.0

In my case, if we do not install it or in general if we do not install it, we install the latest one, which is at least what I want. We wait here for a second for the process to finish and here we have it, in principle, Django 5.1 and its dependencies have been installed. If we run a new one:

$ pip freeze

Here we have Django and its dependencies which are the other three that you can see there on the screen.

Virtual environments to have separate environments

Remember that virtual environments are like who says a little box that is isolated from the operating system, so there we usually have all the packages for a project regardless of the jga that we follow in D dango what I mean a project an application in this case an online store is usually linked to only one virtual environment and if you want to create another project in Dyango we usually create another virtual environment And this is because surely those projects are going to work with different packages and therefore, that is to say, in addition to dango we usually install some things taking advantage of the ecosystem that we have in python and in Django we also install different packages, so with that we can, as who says, guarantee exclusive dependencies for a project and not be mixing things up, now it's a good idea to create the requirements file with the requirements here:

$ pip freeze > requirements.txt

Create project in Django

Since we have Django installed we have access to a command called Django admin that we didn't have before if we didn't install the Django Start project package:

$ django-admin startproject mystore

Here you put the name that will be mystore we wait 100,000 years there we have it here we would already have a little folder there we have it and well, with this we finish the objective of this class so let's go to the next one

I agree to receive announcements of interest about this Blog.

Let's create a new project in Django.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro desarrollo web con Django 5 y Python 3 + integración con Vue 3, Bootstrap y Alpine.js.