08-02-2023, 04:46 PM
I am playing around with flask. My directory structure is like so:
|--------flask-test
|----------------app
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
The `venv` folder holds my virtual flask installation. My `__init__.py` is like so:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
This works with no issues however now I would like to split this into two files `__init__.py` and `main.py`. The `main.py` would be in the same directory as `__init__.py`. So far I have tried:
`__init__.py`:
from flask import Flask
app = Flask(__name__)
import main
`main.py`:
from app import app
@app.route("/")
def hello():
return "Hello World!"
However I am getting an error that the module `app` does not exist in `main.py` then I try to run `__init__.py`. What am I doing wrong here? Also where should I put the run method?
|--------flask-test
|----------------app
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------__init__.py
The `venv` folder holds my virtual flask installation. My `__init__.py` is like so:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
This works with no issues however now I would like to split this into two files `__init__.py` and `main.py`. The `main.py` would be in the same directory as `__init__.py`. So far I have tried:
`__init__.py`:
from flask import Flask
app = Flask(__name__)
import main
`main.py`:
from app import app
@app.route("/")
def hello():
return "Hello World!"
However I am getting an error that the module `app` does not exist in `main.py` then I try to run `__init__.py`. What am I doing wrong here? Also where should I put the run method?