For an extra little bit of security I want to change the default django admin url to the custom one, e.g. change mysite.com/admin/ to mysite.com/mysecretadmin/ so that admin is completely unaccessible via default url.
I tried some solutions from the internet, for example I changed urls.py like this:
from django.conf.urls import patterns, url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('api.views',
...,
...,
url(r'^secret-admin-url/', include(admin.site.urls)),
)
Nothing worked for me, sadly. Does anyone know the solution? I use django 1.5.4.
cutteeth :
Refer to the section 'Hooking AdminSite instances into your URLconf' in the url\nbelow\nhttps://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-to-urlconf",
2014-06-11T14:26:45
Shahriar.M :
For those who find this question in recent times. Based on the Django 3.1 docs:\nregister the default AdminSite instance django.contrib.admin.site at the URL /admin/:\n# main project urls.py\nfrom django.contrib import admin\nfrom django.urls import path\n\nurlpatterns = [\n path("admin/", admin.site.urls),\n]\n\nyou can simply change the admin/ url to anything you wish:\nurlpatterns = [\n path("my_custom_url/", admin.site.urls),\n]\n",
2020-11-08T07:04:37
Bruno Vermeulen :
If you do not want to use the default page /admin you can add a secret key to admin. So in urls.py\nurlpatterns = [\n path('admin_eTiOmEthelInEwathbace/', admin.site.urls,),\n]\n\nIf in your template you have a link\n<a href="{% url 'admin:index' %}">Admin</a>\n\nthen this will reference to the above site with url: http://127.0.0.1:8000/admin_eTiOmEthelInEwathbace/\nNow you do not want to publish this secret_key, therefore get it from an environment variable with for example decouple, so urls.py then becomes\nfrom decouple import config\nSECRET_ADMIN = config('SECRET_ADMIN')\n\nurlpatterns = [\n path(f'admin_{SECRET_ADMIN}/', admin.site.urls,),\n]\n",
2020-11-04T08:17:20