So basically, can I have two urls(or paths) for the same view in django? I searched online for this question, but somehow I couldn't find a clear answer(in other word, please don't downvote me because it is a seemingly easy question). Thank you, and please let me know if you have any questions.
CodePudding user response:
Yes, if you have a view some_view
you can define two (or more) paths, for example:
urlpatterns = [
path('foo/', some_view, name='foo'),
path('bar/', some_view, name='bar'),
]
It is even possible to define these in two separate urls.py
. Both will trigger the same view. It is however not very "popular" to have multiple URL patterns for the same view since usually a path explains what it does, for example post/123/delete
likely is a view to delete a Post
object with 123
as primary key.
CodePudding user response:
Yes, you can have multiple URLs for the same view, I would recommend looking at this answer: (Django)How to map two urls to one view?