|
10鱼币
def yzm(request):
# 1. 直接打开
# 1. 直接打开
img, code = check_code()
print(code)
报错信息是
File "D:\软件\djangoProject\djangoProject\urls.py", line 24, in <module>
from app import dl
File "D:\软件\djangoProject\app\dl.py", line 50, in <module>
from app.cs import check_code
File "D:\软件\djangoProject\app\cs.py", line 112, in <module>
with open('static\images\code.png', 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'static\\images\\code.png'
其中 cs.py文件 内容 是
https://fishc.com.cn/thread-229436-1-1.html
跟上一个帖子一样的道理,相对路径与绝对路径的问题:
cs.py的112行改成:
with open(os.path.join(os.path.dirname(__file__), 'static\images\code.png'), 'wb') as f:
同样的,如果os库没有导入的话需要在前面导入
|
最佳答案
查看完整内容
跟上一个帖子一样的道理,相对路径与绝对路径的问题:
cs.py的112行改成:
with open(os.path.join(os.path.dirname(__file__), 'static\images\code.png'), 'wb') as f:
同样的,如果os库没有导入的话需要在前面导入
|