Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect request to admin interface

After enabling the administrator interface and starting the development web server on e.g. 128.0.0.1:8000, I am able to reach the admin interface on

128.0.0.1:8000/admin.

Obviously due the following URL namespace

url(r'^admin/', include(admin.site.urls)).

What do I have to do redirect requests on 128.0.0.1:8000/ automatically to 128.0.0.1:8000/admin?

The URL namespace

url(r'^$/', include(admin.site.urls))

does not seem to be the solution.

like image 789
Simon Avatar asked Jan 30 '12 20:01

Simon


People also ask

Can you redirect a URL to a specific page?

Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.

How do I create a redirect URL?

Redirects allow you to forward the visitors of a specific URL to another page of your website. In Site Tools, you can add redirects by going to Domain > Redirects. Choose the desired domain, fill in the URL you want to redirect to another and add the URL of the new page destination. When ready, click Create.

CAN POST request be redirected?

in response to a POST request. Rather, the RFC simply states that the browser should alert the user and present an option to proceed or to cancel without reposting data to the new location. Unless you write complex server code, you can't force POST redirection and preserve posted data.


1 Answers

You can also use path instead of url which has been deprecated and is no longer available in Django 4.

from django.views.generic.base import RedirectView

urlpatterns = [
    path('', RedirectView.as_view(url='/admin')),
    path('admin/', admin.site.urls),
    ...
] 
like image 162
davidjbrady Avatar answered Sep 28 '22 18:09

davidjbrady