Can I edit the Django administration screen to dis

2019-01-27 00:17发布

Is there a way to display html data on a specific page in the django administrator feature?

For example, let's say I have a programming-language Model, and for each language in the django administrator page, beneath the editing fields section, it display a picture with an html paragraph. A 'Python' language will show a snake picture and some description about it.

Thanks, Alon.

1条回答
甜甜的少女心
2楼-- · 2019-01-27 00:52

Override admin change_form.html for your model with

{% extends "admin/change_form.html" %}

{% block after_related_objects %}
    {# put your html here #}
{% endblock %}

(Django 1.8 note) Make sure you have specified 'DIRS' key in TEMPLATES dict (settings.py)

'DIRS': [
        os.path.join(BASE_DIR, 'templates'),
    ],

templates/

----admin/

--------app_name/

------------modelname/

----------------change_form.html

查看更多
登录 后发表回答