Home > Mobile >  Using two urls for the same view in django?
Using two urls for the same view in django?

Time:10-16

So basically, how can I have two urls(or paths) for the same view in django?

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:

You can have multiple URLs for the same view, I would recommend looking at this answer: How to map two urls to one view?

  • Related