
Hello everyone!
When I first came across Flask, I immediately had a question about building a project architecture.
After reading a couple of articles on Habré ( https://habr.com/en/post/275099/ and https://habr.com/en/post/421887/ ), I remembered my experience in creating projects on Django, and decided to make a tool thanks to which you don’t have to think about architecture, but at the same time you can use all the features of Flask.
Installation
$ pip install Flask-DJ
Project creation
You can create a project either using the console (the -t -st flags are used for templates and static files)
$ flask-dj startproject app
Or you can create the setup.py file
(the flags
need_templates = True, need_static = True are used for templates and static files ).
from flask_dj import startproject
from os import getcwd
your_project_name = 'app'
project_dir = getcwd()
startproject(your_project_name, project_dir)
The result should be the following structure
(static and templates will appear when the corresponding flags are specified)
app/
app/
__init__.py
config.py
urls.py
manage.py
Application creation
( ).
( index ).
$ python manage.py startapp index
:
app/
app/
__init__.py
config.py
urls.py
index/
forms.py
models.py
urls.py
views.py
manage.py
(view)
Hello world, :
def index():
return "Hello world"
URL
index:
from utils.urls import relative_path
from .views import index
urlpatterns = [
relative_path("", index),
]
:
from utils.urls import add_relative_path, include
urlpatterns = [
add_relative_path("/", include("index.urls")),
]
$ python manage.py runserver
,

P.S.
.
, :
Upd1 buriy