[Django]-Using two urls for the same view in django?

6👍

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.

Leave a comment