import a file in a folder python


I want to import a file from a folder in my replit project. I’m using the same project to do a website , with flask. This is the structure

project ——|——
          |—— static ——|—— Templates —— index.html

I’m using a function who keep alive the bot using uptime robot. Before, I didn’t need a website. The flask app just print in a website output I’m alive. But now, I want to create a full website with flask using HTML. The HTML isn’t a problem. The problem is that, in the structure, you can see that is in the folder static and the file isn’t. Because the function to keep alive the bot is in, I can’t import it like that from flask_ import keep_alive. I don’t know how to import it. Can you help me?


You need to start from the root directory of the project:

from static.flask_ import keep_alive

But why do you have have dynamic code in a folder named static? I suggest moving the folder to the root of the project then you can use the import you already have.

Side note: in python, we typically use underscores to separate words in names. Ending a filename with an underscore is unusual.

Answered By – Code-Apprentice

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published