I have been designing websites with Django for a while and I have also designed various sites. But here is a question that comes to mind at the beginning of any new project:
What is the best a URLs architectural Design that creates both logical and meaningful URLs path as well as plugable apps?
Parctical Example And Problem
I will explain my question with a practical example. Suppose that we have project with these features:
-
It has three applications called
Shop
,Blog
andSupport
. -
It has three
URL
section:2.1. Public section: that start with
/
.2.2. Consumer panel: that start with
/panel
.2.3. Administrator panel: that start with
/administrator
. -
Each application has 3 views. For example
Shop
has:public_shop_view
,panel_shop_view
andadministrator_shop_view
.
Now, What is the best URL
design for this project? I describe two possible answers here for URLs
desing.
Solution 1:
project/urls.py
path('', include('Shop.urls', namespce='Shop')),
path('', include('Blog.urls', namespce='Blog')),
path('', include('Support.urls', namespce='Support')),
Shop/urls.py
path('shop/', views.public_shop_view, name='public_shop_view'),
path('panel/shop/', views.panel_shop_view, name='panel_shop_view'),
path('administrator/shop/', views.administrator_shop_view, name='administrator_shop_view'),
Blog/urls.py
path('blog/', views.public_blog_view, name='public_blog_view'),
path('panel/blog/', views.panel_blog_view, name='panel_blog_view'),
path('administrator/blog/', views.administrator_blog_view, name='administrator_shop_view'),
Support/urls.py
path('support/', views.public_support_view, name='public_support_view'),
path('panel/support/', views.panel_support_view, name='panel_support_view'),
path('administrator/support/', views.administrator_support_view, name='administrator_support_view'),
Solution 2: In this solution we create three app (Public, Panel, Administrator) that just have urls.py
file(to follow the interface strategy):
project/urls.py
path('', include('Public.urls', namespce='Interface')),
path('panel/', include('Panel.urls', namespce='Panel')),
path('administrator/', include('Administrator.urls', namespce='Administrator')),
Public/urls.py
from Support import views as support_views
from Blog import views as blog_views
from Shop import views as shop_views
path('support/', support_views.public_support_view, name='public_support_view'),
path('blog/', blog_views.public_blog_view, name='public_blog_view'),
path('shop/', shop_views.public_shop_view, name='public_shop_view'),
Panel/urls.py
from Support import views as support_views
from Blog import views as blog_views
from Shop import views as shop_views
path('support/', support_views.panel_support_view, name='panel_support_view'),
path('blog/', blog_views.panel_blog_view, name='panel_blog_view'),
path('shop/', shop_views.panel_shop_view, name='panel_shop_view'),
Administrator/urls.py
from Support import views as support_views
from Blog import views as blog_views
from Shop import views as shop_views
path('support/', support_views.administrator_support_view, name='administrator_support_view'),
path('blog/', blog_views.administrator_blog_view, name='administrator_blog_view'),
path('shop/', shop_views.administrator_shop_view, name='administrator_shop_view'),
Now, What is the best practice? Solution 1 or solution 2 or other solution?
Aucun commentaire:
Enregistrer un commentaire