user16360833
user16360833

Reputation:

import a file in a folder python

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

project ——|—— main.py
          |
          |—— static ——|—— Templates —— index.html
                        |
                        |—— flask_.py

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 flask_.py is in the folder static and the main.py file isn’t. Because the function to keep alive the bot is in flask_.py, I can’t import it like that from flask_ import keep_alive. I don’t know how to import it. Can you help me?

Upvotes: 0

Views: 261

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83537

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 flask_.py 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.

Upvotes: 1

Related Questions