如何为django管理员创建自定义页面? [英] How can I create custom page for django admin?

查看:102
本文介绍了如何为django管理员创建自定义页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为没有型号的管理面板创建自定义页面。首先我将index.html复制到项目文件夹:

I want to create custom page for admin panel without model. For first i copy index.html to project folder:

mysite/
    templates/
        admin/
            index.html

然后添加到应用程序阻止我的代码:

Then add to apps block my code:

<div class="module">
    <table summary="{% blocktrans with name="preferences" %}Models available in the preferences application.{% endblocktrans %}">
        <caption><a href="preferences" class="section">{% blocktrans with name="preferences" %}Preferences{% endblocktrans %}</a></caption>
            <tr>
                <th scope="row"><a href="preferences">Preferences</a></th>
                <td><a href="preferences" class="changelink">{% trans 'Change' %}</a></td>
            </tr>
    </table>
</div>

这样做很好,然后我创建新页面/templates/admin/preferences/preferences.html和
添加到urls.py:

This works good, then I create new page /templates/admin/preferences/preferences.html and add to urls.py:

url(r'^admin/preferences/$', TemplateView.as_view(template_name='admin/preferences/preferences.html')),

并将代码添加到preferences.html:

And add code to preferences.html:

{% extends "admin/base_site.html" %}
{% block title %}Test page{% endblock %}

运行它,看到错误所请求的管理页面不存在的消息。我做错了什么?

Run it and see message with error "The requested admin page does not exist.". What I do wrong?

推荐答案

您需要在之前添加您的管理URL 管理员本身:

You need to add your admin URL before the URL patterns of the admin itself:

urlpatterns = patterns('',
   url(r'^admin/preferences/$', TemplateView.as_view(template_name='admin/preferences/preferences.html')),
   url(r'^admin/', include('django.contrib.admin.urls')),
)

这样一来,Django的管理员就不会处理该URL。

This way the URL won't be processed by Django's admin.

这篇关于如何为django管理员创建自定义页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆