验证码加载不出来
报错信息如下:
[2024-07-17 13:42:37][django.server.log_message():212] [INFO] "GET /api/init/settings/ HTTP/1.1" 200 502
[2024-07-17 13:42:37][dvadmin.utils.exception.CustomExceptionHandler():68] [ERROR] Traceback (most recent call last):
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\backend\dvadmin\system\views\login.py", line 39, in get
imgage = captcha_image(request, hashkey)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\captcha\views.py", line 88, in captcha_image
charimage = Image.new("L", getsize(font, " %s " % char), "#000000")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\captcha\views.py", line 33, in getsize
return font.getsize(text)
^^^^^^^^^^^^
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
Traceback (most recent call last):
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\backend\dvadmin\system\views\login.py", line 39, in get
imgage = captcha_image(request, hashkey)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\captcha\views.py", line 88, in captcha_image
charimage = Image.new("L", getsize(font, " %s " % char), "#000000")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\workspace\django-vue3-admin\.venv\Lib\site-packages\captcha\views.py", line 33, in getsize
return font.getsize(text)
^^^^^^^^^^^^
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
原因是django-simple-captcha==0.5.17与pillow库版本不兼容,更新captcha到最新版本。
用户管理手机号码查询条件不生效
原因是后端未添加mobile字段的查询,在backend/dvadmin/system/views/user.py文件中修改 class UserViewSet,在filter_fields中加入mobile。
...
filter_fields = ["name", "username", "mobile", "gender", "is_active", "dept", "user_type"]
search_fields = ["username", "name", "dept__name", "role__name"]
...
登录日志创建时间查询条件不生效
注释掉视图集中extra_filter_class属性,代码中设置为空,覆盖掉了默认的查询字段。
"""
登录日志接口
list:查询
create:新增
update:修改
retrieve:单例
destroy:删除
"""
queryset = LoginLog.objects.order_by('-create_datetime')
serializer_class = LoginLogSerializer
# extra_filter_class = []
登录日志关键字查询不生效
原因是LoginLogViewSet类没有配置search_fields,在backend/dvadmin/system/views/login_log.py文件中修改 class LoginLogViewSet,在search_fields中加入关键字轮询查询字段。
"""
登录日志接口
list:查询
create:新增
update:修改
retrieve:单例
destroy:删除
"""
queryset = LoginLog.objects.all()
serializer_class = LoginLogSerializer
search_fields = ['username', 'ip']
#extra_filter_class = []
登录日志省份城市等位置信息不显示
原因是我是在本地运行,访问ip是127.0.0.1,ip未解析出地址信息。ip解析是调用了一个接口完成的https://ip.django-vue-admin.com/ip/analysis
操作日志关键字查询不生效
同登录日志原因相同,未设置search_fields