我正在尝试实现load more按钮,所以我为load json data编写了这个视图,但是我不明白为什么我会得到这个错误。No user profile found matching the query Raised by: members.views.UserProfileUpdate
这是我的观点:
class PostJsonListView(View):
def get(self, *args, **kwargs):
print(kwargs)
upper = kwargs.get('num_posts')
lower = upper - 3
posts = list(Blog.objects.values()[lower:upper])
posts_size = len(Blog.objects.all())
max_size = True if upper >= posts_size else False
return JsonResponse({'data': posts, 'max': max_size}, safe=False)这是我的博客应用urls.py
path('posts-json/<int:num_posts>',PostJsonListView.as_view(),name='json-view')这是我的会员应用程序urls.py
path('<slug:slug>/', UserProfileUpdate.as_view(), name='update-profile'),
如果我放入像这样的错误url,http://127.0.0.1:8000/sassassdsadasdd/会给出同样的错误No user profile found matching the query Raised by: members.views.UserProfileUpdate
发布于 2021-10-13 06:02:41
您在UserProfileUpdate视图中,使用slug获取配置文件对象,如下所示:
Profile.objects.get(username=slug)但是!您应该使用get_object_or_404快捷方式函数。
from django.shortcuts import get_object_or_404
get_object_or_404(Profile, username=slug)https://stackoverflow.com/questions/69547622
复制相似问题