How to create a Django Project Requirements.txt File

The requirement.txt file is an important document when building a Django project since it lists not only the packages necessary to run the code but also registers their respective versions.

In simpler terms, the requirement.txt file is a document or file that lists all the modules required for the Django project to work. Examples of modules or packages required for your Django project to work to its full potential are Django-crispy-forms(forms),  Pillows(manage Images), Matplotlib, and many more. 

Why do you need the requirement.txt file?

  • The file gives you the exact packages required for your project to function efficiently.
  • While deploying your project to production or any other environment we need an idea of the packages installed in the project.
  • It saves development and deployment time.

How can we create a requirements.txt file?

Firstly, we have to create our virtualenv and activate it. 

You may need to know that typing pip freeze in your command line terminal will also display the lists of all of the modules that you have installed for your project.

This is shown below:

The above list all of the modules you have installed for your project.

Now, let's list all the modules and store them in a text file named "requirement.txt" file. 

pip freeze > requirement.txt

The above line of code will store the whole modules or packages in the requirement.txt file. 

Now, we have the requirement.txt file created that displays a list of all the modules that you installed for your project.

When going live with your Django project, you want this requirement.txt file in the root directory of your project where the manage.py file resides.