Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change django admin "view site" link to custom absolute url

Tags:

I have REST API built on Django and JS application. Both are on different domains. How to change django admin "view site" link in such way so it will open JS application? I've tried to pass absolute link (https://docs.djangoproject.com/es/1.10/ref/contrib/admin/#django.contrib.admin.AdminSite.site_url), but looks like it does not work - only relative paths allowed

like image 369
Dmitrijs Zubriks Avatar asked Nov 24 '16 08:11

Dmitrijs Zubriks


People also ask

Can we customize Django admin panel?

The Django admin is a powerful built-in tool giving you the ability to create, update, and delete objects in your database using a web interface. You can customize the Django admin to do almost anything you want.

How do I change the appearance of Django admin?

To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.

How do I change the admin template in Django?

To do so, you will have to change the project's settings.py . Find the TEMPLATES section and modify accordingly. To override the default template you first need to access the template you want to modify from the django/contrib/admin/templates/admin directory.


2 Answers

In Django 1.11.5, it seems that : from django.contrib import admin and admin.site.site_url = 'https:....' in the admin.py file is enough

like image 174
HamzDiou Avatar answered Sep 21 '22 18:09

HamzDiou


I prefer resetting admin.site.site_url in urls.py, along with other site changes (instead of doing this in an admin.py file, cause a project can have serveral admin.py)

# urls.py
admin.site.site_url = ''  # Removes the 'View Site' link
admin.site.site_header = 'My Site'
like image 33
Nitin Nain Avatar answered Sep 18 '22 18:09

Nitin Nain