- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的夹层网站页面底部创建一个 “页面上次更新者(用户名)”于(日期)”
行。我已成功获取日期部分语法:
{{ page.updated|date:"M d, Y" }}
但用户名似乎更复杂。我在 django_admin_log 中有一个很好的列表,其中包含 action_time
、user_id
和 object_id
,我可以从内部访问和显示 object_id
我的模板使用 {{ page.id }}.
用户名位于 auth_user
中,在过去,我会在 user_id
上输入一些带有良好表连接的 SQL 来检索此信息并显示它。
我似乎无法正确理解语法 - 这种事情看起来很有希望:
page.objects.raw("select id, title from page")
但无论我如何尝试使用 {{ xxx }} 或 {% xxx %}
将其按摩到我的 base.html
中,我似乎总是得到一个错误。
谢谢各位指点
最佳答案
我找到了一种方法来做到这一点:
我创建了一个自定义标签,保存在/appname/templatetags/appname_tags.py中,代码如下:
from django import template
from django.db import connection
register = template.Library()
@register.inclusion_tag(‘appname/_updated_by.html')
def updated_by(pageid):
cursor = connection.cursor()
cursor.execute('select user_id from django_admin_log where object_id = %s order by id desc limit 1', [pageid])
userid_set = cursor.fetchone()
userid = userid_set[0]
cursor.execute('select first_name, last_name from auth_user where id = %s', [userid])
username = cursor.fetchone()
return {'first_name': username[0],'last_name': username[1]}
此标记通过/appname/templates/appname/_updated_by.html 呈现,其中仅包含:
{{ first_name }} {{ last_name }}
然后通过以下代码从 base.html 调用整个内容:
{% load appname_tags %}
然后在适当的位置添加:
Page Last Updated: {{ page.updated|date:"d/n/Y" }} by {% updated_by page.id %}
希望这对某人有帮助,我很想听听是否有更简单/更优雅的方法来做到这一点!
关于mysql - 尝试制作 Django/Mezzanine "Page last updated by on date",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26870294/
我正在尝试在我的夹层网站上安装一个新模板。我的夹层是 4.2.2 版,Django 是 1.9.7 版。这是我所做的: 与 DEBUG = true 我创建了一个名为“template_app”的新应
这是文档:(我不太清楚)。 http://mezzanine.jupo.org/docs/content-architecture.html#page-templates 这是 dollydagr 回
我遵循了描述的方法 here . 在索引页上,我有一个表格可以让我在网站语言之间切换。我添加了“next”post 属性启用重定向到页面的正确语言版本。 {% csrf_token %} 如第
如何准确地、一步一步地安装夹层主题? 例如,Moderna free theme . 最佳答案 先决条件: 0) 版本控制 Python 2.7.6. Django 1.6.10 Mezzanine
我可以在用于其他页面的模板中访问夹层页面库中的内容吗? 例如,我有一个图库页面,其中显示了我在 Django Admin 中添加到“媒体库”的图像集合。该页面工作正常并显示我为该页面选择的所有图像。
我正在建立一个简单的网站,我想为 UI 集成 angularjs。然而,似乎 CMS 接管了一切并提供了一切,包括我想通过 angularjs 提供的任何东西。 我的 urls.py 文件: urlp
我一直在为我的个人网站选择一个 django CMS,我认为 Mezzanine 将是最能满足我需求的一个。但我发现我无法将它安装在 Webfaction 上。各种各样的错误都在发生,对于像我这样的菜
我在 Django 1.10.7 和 Python 3.6.2 上有 Mezzanine 4.2.3。 Mezzanine 在管理员中附带了一个 TinyMCE 编辑器。我不确定编辑器上的版本是什么,
我不确定我必须为一个组分配什么权限,以便该组的用户可以登录到他们分配到的特定夹层站点的管理区域。用户检查了员工状态。 我希望该组对设置的访问权限有限,例如: sites (all) redirects
我无法让 Django 的夹层框架接受将视频嵌入到我的博客文章中。我尝试使用 富文本编辑器 的 video 标签,尝试编辑 html 代码并插入 iframe YouTube提供给我,但没有成功。一旦
我有一个非常大的问题......我正在尝试制作一个生产服务器(在 CentoOS 6 上)以在其上部署一个夹层 cms。问题是我已经研究了很多,但找不到有用的东西。我对此有点菜鸟,但我已经尝试过使用
我正在尝试使用 HTML5 UP!使用 Django/Mezzanine 元素时,我在让 skeljs 正确加载样式 css 文件时遇到问题。 这就是我在 base.html 文件中加载文件的方式:
我在使用 mezzanine 的 Django 应用程序中遇到问题. 我指定了可以通过这种方式搜索的模型: SEARCH_MODEL_CHOICES = ('organization-pages.Cu
我正在尝试将验证码添加到 Mezzanine 中的联系表单中使用mezzanine-captcha 。但是,我收到 no such table: captcha_captchastore 异常。显然,
我在 django 中编写了一些模型,这些模型显示为可排序列表,您可以在其中添加尽可能多的元素,在某些情况下这很好,但在其他情况下,我想将其限制为仅添加新的旧部分并推迟此处添加新信息时的页面是我到目前
我是Python新手。我一直在研究 Mezzanine,并尝试将其与我现有的 Django 项目集成。 正如 Mezzanine 的常见问题解答中所述,我更新了 Django 项目的 settings
在夹层中,我正在使用墨盒,并且我想在将运输详细信息邮寄给用户时更改发件人电子邮件。默认值为 do_not_reply@WINCTRL-4UBSUNC。我可以在哪里更改此设置?另外,我想向管理员发送有关
Python 新手,正在尝试部署博客。我遵循了 Heorku 关于 Getting Started with Python on Heroku 的文档.它提到我需要添加一个 Procfile,所以我添
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 7年前关闭。 Improve this
我在其他地方没有任何运气,所以我很感激我在这里得到的任何帮助/建议。以下是我想做的事情的概要: 本地开发环境Mezzanine ,它还将为 S3 提供的前端、静态/媒体集成 Bootstrap。 使用
我是一名优秀的程序员,十分优秀!