django-models - 如何获得 QuerySet 的字段
问题描述
当我需要从 post.title 文本创建 qr cod 时,我在管理面板中添加帖子
我尝试使用 django-qr-code 库和 ContactDetail 模型,但我得到错误:** 之后的类型对象参数必须是映射,而不是 Post
views.py def 索引(请求):
# Use a ContactDetail instance to encapsulate the detail of the contact.
posts = Post.objects.all()
contact_detail = ContactDetail(
first_name=Post.objects.get())
# Use a WifiConfig instance to encapsulate the configuration of the connexion.
# Build context for rendering QR codes.
context = dict(
posts=posts,
contact_detail=contact_detail,
)
# Render the index page.
return render(request, 'blog/post_list.html', context=context)
模型.py
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=400)
html
{% qr_for_contact contact_detail=contact_detail size='S' %}
解决方案
推荐阅读
- c# - 从另一个项目调用时获取项目的输出目录
- javascript - 如何在特定频道上向另一个 Discord 服务器发送消息?
- php - PHPMailer 不工作,而 php mail() 工作
- authentication - 具有多个 Webassembly 应用程序的托管部署的 Blazor 身份验证
- python - 使用装饰器管理函数内部的属性
- templates - PHPWord(模板):调整现有表格单元格的属性(填充/边框)
- android - 如何停止/取消活动中的任务?Android中的runOnUiThread?
- conditional-statements - 赛普拉斯 ckeck 是否存在任何字段中的文本
- pyspark - 如何在工作节点的 HDInsight pyspark 中写入 blob
- jenkins - 如何在声明式管道(Jenkinsfile)中配置动态参数?