What's the best practice to manage api-related urls? #4902
Unanswered
TGoddessana
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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