Reputation: 121
How can a page be linked to the admin page of django? I have tried changing the base.html page but it is getting reflected to all the html pages of the admin. Can this be linked just to the index page of admin where all the app are listed.
Upvotes: 5
Views: 2895
Reputation: 824
Reference : How to override and extend basic Django admin templates?
You can customize the index template as:
# urls.py
...
from django.contrib import admin
admin.site.index_template = 'admin/my_custom_index.html'
admin.autodiscover()
and place your template in /templates/admin/my_custom_index.html
{% extends "admin/index.html" %}
{% block content %}
{{block.super}}
<div>
<h1>Others</h1>
<a href="/v1/my_new_link/">A new link menu</a>
</div>
{% endblock %}
Upvotes: 0
Reputation: 122
You have to override Django admin index.html page
First step:
Create new file in your templates folder call it 'index.html' for example. For example file path will be like: 'YOUR_PROJECT/templates/admin/index.html' and copy the following code:
{% extends "admin/index.html" %}
{% block content %}
<h1>YOUR EXTRA CODE</h1>
{{ block.super }}
{% endblock %}
Second step:
Create new file in YOUR_MAIN_PROJECT folder -alongside settings.py- call it admin.py and copy the following code:
from django.contrib.admin import AdminSite
class CustomAdmin(AdminSite):
index_template = 'admin/base_site.html'
custom_admin_site = CustomAdmin(name='admin')
Third step:
In YOUR_APP admin.py file put the following code:
from YOUR_MAIN_PROJECT.admin import custom_admin_site
from .models import YOUR_MODEL_1, YOUR_MODEL_2
custom_admin_site.register(YOUR_MODEL_1)
custom_admin_site.register(YOUR_MODEL_2)
I hope this helps, your respond is appreciated
Upvotes: 5
Reputation: 1966
<a href="{% url 'admin:index' %}">Admin panel</a>
But you have to have to add admin.site.urls in your URLS.py
url(r'^admin/', include(admin.site.urls)),
But if you are trying to render admin site in one of your sites (let's say index):
url(r'', include(admin.site.urls)),
That should do the trick
Upvotes: 1