Я попытался запустить runserver, я проверил все страницы, все в порядке, кроме моей домашней страницы, которая выдала ошибку. TypeError в / ожидаемой строке или объекте, подобном байтам.
Traceback (most recent call last):
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\views\generic\list.py", line 142, in get
self.object_list = self.get_queryset()
File "C:\Users\ANTON\Desktop\Learn Django\cloneBlogProject\mySite\blog\views.py", line 19, in get_queryset
return Post.objects.filter(published_date__lte = timezone.now).order_by('-published_date')
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\query.py", line 904, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\query.py", line 923, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\sql\query.py", line 1350, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\sql\query.py", line 1377, in _add_q
child_clause, needed_inner = self.build_filter(
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\sql\query.py", line 1311, in build_filter
condition = self.build_lookup(lookups, col, value)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\sql\query.py", line 1165, in build_lookup
lookup = lookup_class(lhs, rhs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\lookups.py", line 22, in __init__
self.rhs = self.get_prep_lookup()
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\lookups.py", line 72, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\fields\__init__.py", line 1355, in get_prep_value
value = super().get_prep_value(value)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\fields\__init__.py", line 1215, in get_prep_value
return self.to_python(value)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\db\models\fields\__init__.py", line 1316, in to_python
parsed = parse_datetime(value)
File "C:\Users\ANTON\Anaconda3\envs\cloneBlog\lib\site-packages\django\utils\dateparse.py", line 107, in parse_datetime
match = datetime_re.match(value)
Exception Type: TypeError at /
Exception Value: expected string or bytes-like object
И эта ошибка указывает на исходный код views.py в этом классе.
from django.views.generic import ListView
from django.utils import timezone
class PostListView(ListView):
model = Post
def get_queryset(self):
return Post.objects.filter(published_date__lte = timezone.now).order_by('-published_date')
Это мой models.py файл.
from django.db import models
from django.utils import timezone
from django.urls import reverse
# Create your models here.
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
create_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(null=True, blank=True)
def publish(self):
self.published_date = timezone.now
self.save()
def approveComments(self):
return self.comments.filter(approveComments=True)
def get_absolute_url(self):
return reverse("post_detail", kwargs={"pk": self.pk})
def __str__(self):
return self.title
Пожалуйста, помогите мне устранить ошибку. Спасибо.