#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 | |-- ************************************************************************
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źć ( ͡°͜ʖ͡°)
A zauważyliście, że na tych protestach to są właściwie sami mężczyźni? A gdzie rolniczynie, hodowczynie, transportowczynie, przetwórczynie i inne agrobiznesmenki? Czy sprawy nie powinna zbadać pani ministra do spraw równości?
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
|
|-- ************************************************************************
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(
'servicesblueprint',
_name,
urlprefix=''
)
apps_init:
def registerblueprints(app):
for modulename in ('authentication', 'home', 'services'):
module = importmodule('apps.{}.routes'.format(modulename))
app.registerblueprint(module.blueprint)
"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źć ( ͡° ͜ʖ ͡°)