Felix-微信(Felixzfb) 2018-12-26 21:33 采纳率: 0%
浏览 2046

Django实现Web应用显示单个主题时出现错误: 'function' object has no attribute 'entry_set'

1。 实现显示单个主题时,点击单个主题出现以下错误

'function' object has no attribute 'entry_set'

Request Method: GET

Request URL: http://localhost:8000/topics/(%3FP1%5Cd+)/

Django Version: 2.1.4

Exception Type: AttributeError

Exception Value: 'function' object has no attribute 'entry_set'

Exception Location: D:\Python_env\learning_log\learning_logs\views.py in topic, line 22

Python Executable: D:\Python_env\learning_log\11_env\Scripts\python.exe

  1. 源代码如下
from django.shortcuts import render
from .models import Topic

# Create your views here.

def index(request):
    return render(request, 'learning_logs/index.html')


def topics(request):
    # 显示所有的主题
    topics = Topic.objects.order_by('date_added')
    context = {'topics': topics}
    return render(request, 'learning_logs/topics.html', context)


def topic(request, topic_id):
    """显示单个主题及其所有的条目"""
    topic = Topic.objects.get(id = topic_id)
    entries = topic.entry_set.order_by('-date_added')
    context = {'topic': topic, 'entries': entries}
    return render(request, 'learning_logs/topic.html', context)

好像问题是出在entries = topic.entry_set.order_by('-date_added')
entry_set没有定义吗?

  • 写回答

3条回答 默认 最新

  • Watch_dou 2019-01-09 13:38
    关注

    topic没有entry_set这个属性,建议调试下面函数中的entries
    def topic(request, topic_id):
    """显示单个主题及其所有的条目"""
    topic = Topic.objects.get(id = topic_id)
    entries = topic.entry_set.order_by('-date_added')
    context = {'topic': topic, 'entries': entries}
    return render(request, 'learning_logs/topic.html', context)

    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功