Heim > Fragen und Antworten > Hauptteil
Wegen Django Admin
的页面都是关联model
的,如何在Admin
后台创建一个页面,不关联任何model
?
三叔2017-06-28 09:25:56
参考文章: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),
]