-2

I struggled with this question for 2 days and has no idea. I have 3 folders containing 3 individual python scripts each folder script run a function.

My question is how can I access them individually?

for only 1 folder, I create, say app.py with all routes inside. but how can I access 3 folder individually and can run individual function?

My file skeleton likes:

app.py (entrance)
|---departmentA
......|-------runme.py
......|-------templates
...........|-----index.html
|---departmentB
......|-------runme.py
......|-------templates
...........|-----index.html
|---departmentC
......|-------runme.py
......|-------templates
...........|-----index.html

Thanks Alex

4

1 Answer 1

-1

File Structure:

app.py
/departmentA
    __init__.py
    routes.py
    runme.py
    /pages/departmentA
        index.html

app.py

from flask import Flask
import departmentA

skill_app = Flask(__name__)
skill_app.register_blueprint(departmentA.bp)

print(departmentA.my_func())

skill_app.run()

/departmentA/init.py

from .routes import bp
from .runme import my_func

/departmentA/routes.py

from flask import Blueprint, render_template
from .runme import my_func

bp = Blueprint('dept_A', __name__, template_folder='pages', url_prefix='/department_A')

@bp.route('/')
def index():
    print(my_func())
    return render_template('departmentA/index.html')

/departmentA/runme.py

def my_func():
    return "Hello World!"

Use same format in other departments.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Thanks I am new to Blueprint. so I copied the same structure and I can type 127.0.0.1/departmentA it will route to departmentA/ and 127.0.0.1/departmentB it will route to departmentB/ right? also the python code will also be run within each department? sorry I am new to Blueprint...need to digest
Ok I copied and it works to open different HTML. However, inside each html, say HTMLA I need to call for example <form method="post" action="/upload2" enctype="multipart/form-data"> so "/upload" will trigger the route in app.py and in HTMLB, will call action "/sendemail" also will trigger the route in app.py......my question is if I have many pages, then app.py will have many routes to handle different HTML's post requests?
oh i misunderstood and after testing it a bit clear now...everything is route to "routes.py" in each department.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.