python - TypeError at/items/join() 参数必须是 str、bytes 或 os.PathLike 对象,而不是 'dict'

标签 python django django-views django-templates

请帮忙,我尝试通过删除部分代码并将其放回原处来追溯我的代码,以查看哪个引发了错误,而这个引发了上述错误。

context = {
    'items': 'Item.objects.all()'
}

这是来 self 的 django-views

from django.shortcuts import render
from .models import Item

def vendors(request):
    return render(request, 'pages/vendors.html', {'title': 'Vendors'})

def items(request):
    context = {
        'items': Item.objects.all()
    }
    return render(request, context, 'pages/items.html', {'title': 'Items'})

def request(request):
    return render(request, 'pages/request.html', {'title': 'Request'})

这是我试图访问的项目页面。

{% extends "pages/base.html" %}
{% load humanize %}

{% block content %}
    {% for item in items %}
    <article class="media content-section">
    <div class="media-body">
        <div class="article-metadata">
        <a class="mr-2" href="#">{{ item.requester }}</a>
        <small class="text-muted">{{ item.date_requesteded|naturaltime }}</small>
        </div>
        <h2><a class="article-title" href="#">{{ item.name }}</a></h2>
        <p class="article-content">{{ item.description }}</p>
    </div>
    </article>
    {% endfor %}
{% endblock content %}

另一个 html 页面运行良好。

最佳答案

context = {
    'items': Item.objects.all(),
    'title': 'Items'
}
return render(request, 'pages/items.html', context)

关于python - TypeError at/items/join() 参数必须是 str、bytes 或 os.PathLike 对象,而不是 'dict',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60965584/

相关文章:

python - 如何获取UpdateView中当前的对象?

python - 试用不使用字典的动态Python变量创建

python - 未找到参数 'detail' ',)' 的 NoReverseMatch at/Reverse。尝试了 1 个模式 :

python - Django 和 Python : Format a FloatField in django form by adding separators

python - 跨三个模型/表将 Python/Django View 写入 "join"

python - 无法在 Django 1.8 中解析静态 JSON 文件

python - pandas如何对一段时间进行分组,然后在组内过滤后返回一个df?

python - 测试电子邮件发送? -Python/Django

Python argparse 如果不是 int 则跳过

python - Django TypeError 字段 'id' 需要一个数字,但得到了 SimpleLazyObject