在django admin中包含google Analytics标签,而无需更改每个页面的模板 [英] Include google analytics tag to django admin without changing the template for every page

查看:60
本文介绍了在django admin中包含google Analytics标签,而无需更改每个页面的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以轻松地将google-analytics javascript代码段包含到django管理页面中? (django 1.10)

Is there a way to include the google-analytics javascript snippet easily into the django admin page ? (django 1.10)

我想这样做,而无需为每个管理页面创建自定义模板,只需将脚本插入所有管理员。

I would like to do that without creating a custom template for each of the admin page, just insert the script in the all admin.

谢谢

推荐答案

您需要覆盖基本管理页面,然后将在那里标记。在模板目录中,创建一个文件夹名称 admin ,在其中创建一个 base_site.html base_site.html 可能看起来像这样:

You need to override the base admin page and put the tag there. Inside Template Directory, create a folder name admin, inside that, create a base_site.html. That base_site.html might look like this:

    {% extends 'admin/base_site.html' %}

    {% load static %}
    {% block extrahead %}{{ block.super }} google analytics codes {% endblock %}

这篇关于在django admin中包含google Analytics标签,而无需更改每个页面的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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