Disable public to download files like .env

Hello

How to disable download files in the root folder?

For example when I go to the link;

https://example.com/.env

It will download the .env file, and

https://example.com/projectfolder/settings.py

It will download the settings.py file.

How can I disable the download access?

Thank you.

This is most likely not a Django issue, but one more related to your file server.
Any answers would depend upon the server you are using and how you have it configured.
In general terms, if this is what you’re seeing, then you definitely have your server configured incorrectly. Your Django application directory should not be within the directory structure served by your web server.