Answer the question
In order to leave comments, you need to log in
Why does the matching query does not exist error occur?
There is a model:
class Novel(models.Model):
slug = models.SlugField()
title_rus = models.CharField(max_length=100)
novel_txt = models.FileField(upload_to='uploads/books_txt', blank=True, null=True)
def novel_text(request, slug):
get_file = Novel.objects.get(slug=slug).novel_txt
file_path = os.path.join('media', str(get_file))
data_file = open(file_path, 'r')
text = data_file.read()
novels = Novel.objects.get(slug=slug).title_rus
context = {
'text': text,
'novels': novels
}
return render(request, 'novels/text.html', context)
{% extends 'novels/base.html' %}
{% load staticfiles %}
{% block content %}
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">{{ novels }}</h1>
</div>
<div class="container">
<div>{{ text|linebreaksbr }}</div>
<div>
{% endblock %}
Traceback (most recent call last):
File "/home/apheyhys/PycharmProjects/jhchase/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/apheyhys/PycharmProjects/jhchase/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/apheyhys/PycharmProjects/jhchase/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/apheyhys/PycharmProjects/jhchase/novels/views.py", line 15, in novel_text
get_file = Novel.objects.get(slug=slug).novel_txt
File "/home/apheyhys/PycharmProjects/jhchase/venv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/apheyhys/PycharmProjects/jhchase/venv/lib/python3.7/site-packages/django/db/models/query.py", line 399, in get
self.model._meta.object_name
novels.models.Novel.DoesNotExist: Novel matching query does not exist.
Answer the question
In order to leave comments, you need to log in
get_file = Novel.objects.get(slug=slug).novel_txt
...
novels.models.Novel.DoesNotExist: Novel matching query does not exist.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question