简体   繁体   English

匹配查询不存在。 在 django

[英]matching query does not exist. in django

Hi This is my Project I needed define two get_absolute_url in my project get_absolute_url one嗨,这是我的项目,我需要在我的项目 get_absolute_url 中定义两个 get_absolute_url

models.py模型.py

def get_absolute_url(self):
    return reverse("cv:resume_detial", args={self.id, self.slug})

urls.py网址.py

path('resume-detial/<int:resume_id>/<slug:resume_slug>', views.ResumeDetialView.as_view(), name="resume_detial"),

views.py视图.py

class ResumeDetialView(View):
    template_name = 'cv/resume-detial.html'
    
    def get(self, request, resume_id, resume_slug):
        resumes = ResumeDetial.objects.get(pk=resume_id, slug=resume_slug)
        return render(request, self.template_name, {'resumes':resumes})

This is a work But other get_absolute_url is does not work这是一项工作,但其他 get_absolute_url 是行不通的

models.py模型.py

def get_absolute_url(self):
    return reverse("cv:project_detial", args={self.id, self.project_slug})

urls.py网址.py

path('project-detial/<int:project_id>/<slug:projects_slug>', views.ProjectDetialView.as_view(), name="project_detial"),

views.py视图.py

class ProjectDetialView(View):
    template_name = 'cv/project-detial.html'
    
    def get(self, request, project_id, projects_slug):
        projects = ResumeDetial.objects.get(pk=project_id, slug=projects_slug)
        return render(request, self.template_name, {"projects":projects})

django messages django 条消息

DoesNotExist at /project-detial/1/todo-django
ResumeDetial matching query does not exist.

I am a beginner and thank you for your help我是初学者,感谢您的帮助

You are doing ResumeDetial.objects.get(pk=project_id, slug=projects_slug) while the ResumeDetial with these criteria doesn't exist.您正在执行ResumeDetial.objects.get(pk=project_id, slug=projects_slug)而符合这些条件的 ResumeDetial 不存在。 You can use filter to search for ResumeDetial's with the given criteria, in case no results are found, it will return an empty list.您可以使用过滤器根据给定的条件搜索 ResumeDetial,如果没有找到结果,它将返回一个空列表。

So, you can change this part of the code:因此,您可以更改这部分代码:

    def get(self, request, project_id, projects_slug):
        projects = ResumeDetial.objects.filter(pk=project_id, slug=projects_slug)
        return render(request, self.template_name, {"projects":projects})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 匹配查询不存在。 Django 错误 - matching query does not exist. Django Error CustomUser 匹配查询不存在。 错误(DJANGO) - CustomUser matching query does not exist. ERROR( DJANGO) 房间匹配查询不存在。 django rest 框架,Django retsframework - Room matching query does not exist. django rest framework, Django retsframework “……匹配查询不存在。”错误,但对象显然存在 - “… matching query does not exist.” error, but object clearly does exist / accounts / register /上的DidsNotExist不存在网站匹配查询。 (Django,Python) - DoesNotExist at /accounts/register/ Site matching query does not exist. (django, python) Django 错误“home.models.Friend.DoesNotExist:好友匹配查询不存在。” - Django error "home.models.Friend.DoesNotExist: Friend matching query does not exist." Django Ajax请求-500个内部服务器错误,带有“不存在匹配的查询。”错误 - Django Ajax requests - 500 INTERNAL SERVER ERROR with “matching query does not exist.” error clients.models.Clients.DoesNotExist:客户端匹配查询不存在。 - django python - clients.models.Clients.DoesNotExist: Clients matching query does not exist. - django python Django - 管理区域 - 我无法从用户中删除用户(用户匹配查询不存在。) - Django - Admin Area - I can't delete a user from users (User matching query does not exist.) 用户匹配查询不存在。 Viber 机器人 Python - User matching query does not exist. Viber bot Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM