I have to make a project blog for my college assignment and am trying to make a page to display all the posts by a particular user but I keep getting this error
Traceback:
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/Grayocean/grayocean.co/blog/views.py" in user_blog_list 121. blogs=get_object_or_404(Blog, author=username)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/shortcuts.py" in get_object_or_404 93. return queryset.get(*args, **kwargs)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/query.py" in get 399. clone = self.filter(*args, **kwargs)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/query.py" in filter 892. return self._filter_or_exclude(False, *args, **kwargs)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/query.py" in _filter_or_exclude 910. clone.query.add_q(Q(*args, **kwargs))
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/sql/query.py" in add_q 1290. clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/sql/query.py" in _add_q 1318. split_subq=split_subq, simple_col=simple_col,
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/sql/query.py" in build_filter 1251. condition = self.build_lookup(lookups, col, value)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/sql/query.py" in build_lookup 1116. lookup = lookup_class(lhs, rhs)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/lookups.py" in init 20. self.rhs = self.get_prep_lookup()
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/fields/related_lookups.py" in get_prep_lookup 115. self.rhs = target_field.get_prep_value(self.rhs)
File "/home/Grayocean/.virtualenvs/myenv/lib/python3.7/site-packages/django/db/models/fields/init.py" in get_prep_value 966. return int(value)
Exception Type: ValueError at /user/rheazes Exception Value: invalid literal for int() with base 10: 'testuser'
views.py
def user_blog_list(self, username):
blogs=get_object_or_404(Blog, author=username)
context={
'posts':blogs
}
return render(request,'blog/user_posts.html',context)
models.py
class Blog(models.Model):
title=models.CharField(max_length=100)
content=models.TextField(blank=True)
image = models.ImageField(upload_to='blog_images', blank=True)
image1= models.ImageField(upload_to='blog_images', blank=True,verbose_name='second image')
image2= models.ImageField(upload_to='blog_images', blank=True,verbose_name='third image')
image3= models.ImageField(upload_to='blog_images', blank=True,verbose_name='fourth image')
image4= models.ImageField(upload_to='blog_images', blank=True,verbose_name='fifth image')
video =models.FileField(upload_to='blog_images',blank=True)
date_posted=models.DateTimeField(default=timezone.now)
author=models.ForeignKey(User, on_delete=models.CASCADE)
likes=models.ManyToManyField(User,related_name='likes',blank=True)
dislikes=models.ManyToManyField(User,related_name='dislikes',blank=True)
urls.py
path('user/<str:username>',views.user_blog_list,name='user-posts'),