Search code examples
pythondjangooperating-systemfakerpathlib

How can I use Pathlib for configuring the settings for the project in Django/Faker?


Right now I'm trying to put some fake data in my database using Faker just for the checking purposes. I've created separate file, but before starting to work with Faker itself and data manipulation, I need to configure the settings for the project in this separate file.

Before DJANGO==3.1 all people have been using OS module and the following syntax.

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')

But now, when Django versions higher than 3.1 switched from OS module to PATHLIB module, how should I write this code using PATHLIB, not OS? Any help would be helpful!


Solution

  • pathlib just replaces filesystem related os module calls as listed in docs.

    It does not have anything to do with os.environ and there is no change to that particular module part