1👍
✅
You can make a view that directs with:
# some_app/urls.py
from django.views.generic import RedirectView
# …
urlpatterns = [
path('d/', include(…)),
path(
'D/<path:path>',
RedirectView.as_view(
url='/d/%(path)s', query_string=True, permanent=True
),
),
]
Note that a redirect will however always result in a GET request, so even if the original request to D/something
is a POST request for example, it will make a GET request to d/something
.
0👍
Any reason why you can’t use a RedirectView at all?
As per the docs:
https://docs.djangoproject.com/en/4.1/ref/class-based-views/base/#redirectview
You can register this as the literal /D/
but redirect to /d/
using the view name and passing on and args or kwargs.
- [Answered ]-Django: How to register User to SimpleHistoryAdmin
- [Answered ]-Count(*) as in Django Orm
- [Answered ]-Django: call standard command from a custom command
Source:stackexchange.com