'How to add custom views or overide views for Django Admin index?
urls.py ->
''''from django.contrib import admin
from django.urls import path
from Administrator import views
admin.site.index_template = 'admin/dashboard.html'
admin.autodiscover()
urlpatterns = [
path('admin/', admin.site.urls),
]
'''
I have added a custom admin_index
template in urls.py
. My doubt is shown in the picture.
My Admin index custom template.Kindly
:
Solution 1:[1]
You can override the AdminSite
and then in this custom admin site class you can override the index
method to provide additional context that you can then use in your template
class CustomAdminSite(admin.AdminSite):
def index(self, request, extra_context=None):
extra_context = extra_context or {}
extra_context['foo'] = 'bar'
return super().index(request, extra_context=extra_context)
Solution 2:[2]
best way to do this, the code below should work.
urlpatterns = [
path('admin/', admin.site.urls , {'extra_context': {
'pro': Product.objects.all(),}}),
]
Solution 3:[3]
Kindly Give your suggestions.
I have searching it for one month.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Iain Shelvington |
Solution 2 | Mohamed Alzohery |
Solution 3 | powerful thoughts |