Wpis z mikrobloga

#python #programowanie #programista15k
Pobrałem flask starter pod aplikację webową, aby w ramach nauki ogarnąć frameworka. Chciałbym tworzyć nowe pliki z kodem źródłowym i importować je, aby nie robić syfu. Przy utworzeniu nowych .py od razu mam import error. Może ktoś orientuje się w takiej strukturze i jest w stanie mi to szybko wyjaśnić lub jest to oczywiście?

< PROJECT ROOT >
|
|-- apps/
| |
| |-- home/ # A simple app that serve HTML files
| | |-- routes.py # Define app routes
| |
| |-- authentication/ # Handles auth routes (login and register)
| | |-- routes.py # Define authentication routes
| | |-- models.py # Defines models
| | |-- forms.py # Define auth forms (login and register)
| |
| |-- static/
| | |-- # CSS files, Javascripts files
| |
| |-- templates/ # Templates used to render pages
| | |-- includes/ # HTML chunks and components
| | | |-- navigation.html # Top menu component
| | | |-- footer.html # App Footer
| | | |-- scripts.html # Scripts common to all pages
| | |
| | |-- layouts/ # Master pages
| | | |-- base-fullscreen.html # Used by Authentication pages
| | | |-- base.html # Used by common pages
| | |
| | |-- accounts/ # Authentication pages
| | | |-- login.html # Login page
| | | |-- register.html # Register page
| | |
| | |-- home/ # UI Kit Pages
| | |-- index.html # Index page
| | |-- page-404.html # 404 page
| | |-- *.html # All other pages
| |
| config.py # Set up the app
| _init_.py # Initialize the app
|
|-- requirements.txt # App Dependencies
|
|-- .env # Inject Configuration via Environment
|-- run.py # Start the app - WSGI gateway
|
|-- ************************************************************************
  • 6
@Arogancky @mikzur @RapRose
Używam PyCharm. Starter: https://appseed.us/product/datta-able/flask/
W apps tworzę nowy folder - "services", a w nim _init i blueprint. Następnie wracam się do głównego init i przy registerblueprint dodaję nazwę folderu.

services_init:
from flask import Blueprint

blueprint = Blueprint(
'services
blueprint',
_name,
url
prefix=''
)

apps_init:
def register
blueprints(app):
for modulename in ('authentication', 'home', 'services'):
module = import
module('apps.{}.routes'.format(modulename))
app.register
blueprint(module.blueprint)
Rozwiązałem już to, jak zwróciłem uwagę na to, co tutaj Wam wklejam.
"module = importmodule('apps.{}.routes'.format(modulename))"
Podałem modulename, ale w tym katalogu ma być kolejny plik routes.py, gdzie występuje import:
"from apps.services import blueprint".
Przepraszam za zamieszanie, świeży jestem i pierwszy raz taki rozbudowany katalog widzę poza main.py to nie jest łatwo mi się odnaleźć ( ͡° ͜ʖ ͡°)