Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError at /items/ join() argument must be str, bytes, or os.PathLike object, not 'dict'

Please help, I tried tracing back my code by removing some part of it and putting it back in to see which one raised the error and this one was the one that raised the above error.

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

This is from my 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'})

This is the items page I was trying to access.

{% 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 %}

The other html page worked fine.

like image 936
Ian Saputra Avatar asked Oct 26 '25 06:10

Ian Saputra


2 Answers

context = {
    'items': Item.objects.all(),
    'title': 'Items'
}
return render(request, 'pages/items.html', context)
like image 114
Alexander Lekontsev Avatar answered Oct 28 '25 22:10

Alexander Lekontsev


While Alexander's answer is correct, it's important to know why in case someone comes across this post.

Django's render() function uses positional arguments in this order:

render(request, template_name, context)

and in OP's post, he passed the context variable twice.

More information in the official documentation.

like image 20
Flavius Teodorof Avatar answered Oct 28 '25 21:10

Flavius Teodorof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!