[Answered ]-How can I import the file in Django from a folder without Errors

1👍

This will work:

from .tools import *

0👍

This issue almost always occurs because you are using a flat file structure for your project, and you try to split the functionality into two files.

1. First method

The easiest way to solve that is to import the file before calling his elements.
First, do this:

import tools

And then if you have for instance a function called "myfunction()" in your tools.py file, then you can use this function as following:

var = tools.myfunction()

2. Second method

If you are making a separate file to do helpful things, why not make it an actual package? It is actually much easier than you would think.

Change up your file structure so that the functionality you want to split out is in a separate folder and includes an empty init.py file. Something like this:

check_project
--- check_app
--- check_project
--- modules
    --- __init__.py
    --- robots.py
    --- tools
        --- __init__.py
        --- tools.py

And then, you can use your previous syntax:

from tools import *

Hope this help.

👤Ikki

Leave a comment