Issue
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?
Solution
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.
Answered By - Code-Apprentice
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.