search

Home  >  Q&A  >  body text

python - Django Admin creates a custom page not associated with any model

Since the pages of Django Admin are all associated with model, how to create a page in the Admin background that is not associated with any model ?

PHP中文网PHP中文网2738 days ago931

reply all(1)I'll reply

  • 三叔

    三叔2017-06-28 09:25:56

    Reference article: Django Admin creates a custom page not associated with any model

    templates

    custom_view.html

    views.py

    @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)

    urls.py

    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),
    ]

    reply
    0
  • Cancelreply