15๐
I am using Django 3.1. This is what I do to achieve this:
in urls.py
from django.shortcuts import redirect
urlpatterns = [
path('', lambda req: redirect('/myapp/')),
path('admin/', admin.site.urls),
path('myapp/', include('myapp.urls'))
]
๐คKen Cloud
5๐
If you look at the documentation for redirect, there are several things you can pass to the function:
- A model
- A view name
- A URL
In general, I think itโs better to redirect to a view name rather than a URL. In your case, assuming your urls.py has an entry that looks something like:
url(r'^$', 'Home.views.index'),
I would instead use redirect like this:
redirect('Home.views.index')
๐คjterrace
- Override create method in django rest generics CreateAPIView
- How to make Django's "DATETIME_FORMAT" active?
- Django 2.0 url parameters in get_queryset
1๐
Also complementing Ken Cloud answer, if you have named urls you can just call the url name:
from django.shortcuts import redirect
urlpatterns = [
path('app/', include('myapp.urls'), name='app')
path('', lambda req: redirect('app')),
path('admin/', admin.site.urls),
]
๐คRenato Prado
- Getting "This field is required" even though file is uploaded
- Django Activity Feed (Feedly Integration?)
Source:stackexchange.com