Albert
Albert

Reputation: 19

FileNotFoundError: [Errno 2] No such file or directory: 'books.json'

I am new to Django I get an error file not found when trying to read a json file that is in the same directory as views.py

# Load books from JSON file
with open('/books.json') as file:
    books = json.load(file)


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

Upvotes: 0

Views: 9564

Answers (1)

Mehan Alavi
Mehan Alavi

Reputation: 327

if your file is books.json you should use "./books.json"

Upvotes: 2

Related Questions