由於Django Admin的頁面都是關聯model的,如何在Admin後台建立一個頁面,不關聯任何model ?
Django Admin
model
Admin
认证0级讲师
參考文章:Django Admin建立不關聯任何model的自訂頁面
custom_view.html
@staff_member_required def custom_view(request): #. . . create objects of MyModel . . . #. . . call their processing methods . . . #. . . store in context variable . . . r = render_to_response('admin/myapp/custom_view.html', context, RequestContext(request)) return HttpResponse(r)
from myapp.views import custom_view urlpatterns = [ url(r'^admin/custom_link/$', custom_view, name='custom_name'), url(r'^$', RedirectView.as_view(url='/admin/')), url(r'^admin/', admin.site.urls), ]
參考文章:Django Admin建立不關聯任何model的自訂頁面
templates
views.py
urls.py