找回密码
 注册
查看: 101|回复: 0

解决 python django 访问时accounts.models.User.DoesNotExist: User matching query does

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2025-5-21 22:30:07 | 显示全部楼层 |阅读模式
Internal Server Error: /accounts/user/info/
0 M: r, ~* v& g" r, p* STraceback (most recent call last):
' k& C# P/ r7 Y2 \  File "C:\Users\admin\python3.8.2-vitual\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
# o- H4 J7 p8 H; d, K0 F) t; L    response = get_response(request)% |* {6 ]* a8 ~6 u4 r
  File "C:\Users\admin\python3.8.2-vitual\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response( o% r0 w+ X! {5 k# i
    response = self.process_exception_by_middleware(e, request)
2 w- W2 m' g) O8 b- c- A  File "C:\Users\admin\python3.8.2-vitual\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response% F( }! A6 a" z& j3 h' Z5 ~5 N% ?
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
4 P3 Q1 o" H" s9 a6 y" L  File "C:\Users\admin\Desktop\testmyproject\accounts\views.py", line 19, in user_info2 T/ {- f9 W8 z& K1 P6 x0 q+ T# M6 b
    user = User.objects.get(pk=1)6 Q$ y  q* V- O$ s6 G: p# K
  File "C:\Users\admin\python3.8.2-vitual\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
0 d) a- z4 G7 R, [. k# G' D# t0 J4 E    return getattr(self.get_queryset(), name)(*args, **kwargs)
' O* a7 V6 X" i: W8 k) T  File "C:\Users\admin\python3.8.2-vitual\lib\site-packages\django\db\models\query.py", line 415, in get" [5 `2 t, q) q/ }' ]% ~
    raise self.model.DoesNotExist(/ s, s1 Q0 [/ I& H/ s' M
accounts.models.User.DoesNotExist: User matching query does not exist.% r) d! o; F; K  Q9 l( F1 _4 `6 G# P
[21/May/2025 22:23:22] "GET /accounts/user/info/ HTTP/1.1" 500 88175
5 s- w& O5 \/ a6 ~0 q" cC:\Users\admin\Desktop\testmyproject\accounts\views.py changed, reloading.9 L* h. H  x& a# `
+ A0 r5 P, p$ o6 \' a. I! c
以为是配置错误了,后来才知道,有可能是我们数据库中没有这条数据。2 V' O- Q7 e4 E8 f4 Z
改成其他的值即可。+ a) c+ D6 I. I4 S$ K. X3 S+ l
在视图函数中user = User.objects.get(pk=2)     pk后面的id要在数据库中真实存在,否则就会报上面的错误。
' B, S! u" @: u4 X
7 q/ i: w0 Q; T& {
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:10 , Processed in 0.018133 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表