You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, first of all I would like to thank everyone for maintaining and contributing to a great template.
In the current template, it seems to be implemented to create a router object and process the urlpatterns for all apis in one file.
Here's what I'd like to ask.
The router object can only be used for ViewSet. This means that when a developer uses a functional view, APIView, the code will look like this: (This is an example code).
In my opinion, this is pretty awkward code. There are duplicate prefixes, and handling other complex urls related to users outside of router.urls seems less readable to me (especially as the app grows and there are more nested urlpatterns). I'd be interested to hear how you solve the problem in my code. Would it be best to use the @action decorator?
you need to look in the config folder to see the urls related to the users api.
In my opinion, both API-related views and pure Django-views are Views that should be registered in urlpatterns. I think it's a bit awkward to look in config/api_routers.py instead of app/urls.py in this situation.
Instead, why not change app/urls.py to something like this?
from django.urls import path
from .views import user_detail_view
from .views import user_redirect_view
from .views import user_update_view
{% if cookiecutter.use_drf == 'y' %}
# import users/ api views...
{%- endif %}
app_name = "users"
urlpatterns = [
path("~redirect/", view=user_redirect_view, name="redirect"),
path("~update/", view=user_update_view, name="update"),
{%- if cookiecutter.username_type == "email" %}
path("<int:pk>/", view=user_detail_view, name="detail"),
{%- else %}
path("<str:username>/", view=user_detail_view, name="detail"),
{%- endif %}
]
{% if cookiecutter.use_drf == 'y' %}
# API URLS
urlpatterns += [
get_router_urls(app_name, UserViewSet),
get_router_urls(app_name, FooView.as_view()),
get_router_urls(app_name, bar_fbv),
]
{%- endif %}
I hope the maintainers don't take this as a bad thing.
Since I'm new to using templates, I wanted to ask those who design and use them what this looks like and what the philosophy behind the existing design is.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, first of all I would like to thank everyone for maintaining and contributing to a great template.
In the current template, it seems to be implemented to create a
router
object and process theurlpatterns
for allapi
s in one file.Here's what I'd like to ask.
router
object can only be used forViewSet
. This means that when a developer uses a functional view,APIView
, the code will look like this: (This is an example code).If you need to use a prefix that already exists, such as users, it would look like this.
In my opinion, this is pretty awkward code. There are duplicate
prefixes
, and handling other complexurl
s related tousers
outside ofrouter.urls
seems less readable to me (especially as the app grows and there are more nested urlpatterns). I'd be interested to hear how you solve the problem in my code. Would it be best to use the@action
decorator?config
folder to see theurls
related to the users api.In my opinion, both
API-related views
andpure Django-views
are Views that should be registered in urlpatterns. I think it's a bit awkward to look in config/api_routers.py instead of app/urls.py in this situation.Instead, why not change
app/urls.py
to something like this?I hope the maintainers don't take this as a bad thing.
Since I'm new to using templates, I wanted to ask those who design and use them what this looks like and what the philosophy behind the existing design is.
Beta Was this translation helpful? Give feedback.
All reactions