gpt4 book ai didi

python - 文件未找到错误: [WinError 3] The system cannot find the path specified: ''

转载 作者:行者123 更新时间:2023-12-01 07:21:52 29 4
gpt4 key购买 nike

当我执行 runserver 并尝试访问 API 时,出现此错误:

FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

我检查导入、模型、序列化器、 View 集和 URL。不知道什么意思?

这里有错误的屏幕截图:

API当我访问: http://127.0.0.1:8000/api/v1.0/notes/

时出现异常
Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/api/v1.0/notes/

Django Version: 2.2.4
Python Version: 3.7.4
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'note',
'rest_framework']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

The traceback is:

Traceback:

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\core\handlers\base.py" in _get_response
145. response = self.process_exception_by_middleware(e, request)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\core\handlers\base.py" in _get_response
143. response = response.render()

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\template\response.py" in render
106. self.content = self.rendered_content

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\response.py" in rendered_content
70. ret = renderer.render(self.data, accepted_media_type, context)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\renderers.py" in render
725. context = self.get_context(data, accepted_media_type, renderer_context)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\renderers.py" in get_context
656. raw_data_post_form = self.get_raw_data_form(data, view, 'POST', request)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\renderers.py" in get_raw_data_form
564. data = serializer.data.copy()

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\serializers.py" in data
559. ret = super().data

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\serializers.py" in data
265. self._data = self.get_initial()

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\serializers.py" in get_initial
409. for field in self.fields.values()

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\utils\functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\serializers.py" in fields
360. for key, value in self.get_fields().items():

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\serializers.py" in get_fields
1056. fields[field_name] = field_class(**field_kwargs)

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\rest_framework\fields.py" in __init__
1503. allow_folders=allow_folders, required=required

File "C:\Users\lrond\Desktop\projectEnreda\env\lib\site-packages\django\forms\fields.py" in __init__
1109. for f in os.scandir(self.path):

Exception Type: FileNotFoundError at /api/v1.0/notes/
Exception Value: [WinError 3] El sistema no puede encontrar la ruta especificada: ''

序列化器.py

from .models import Note
from rest_framework import serializers

class NoteSerializer(serializers.ModelSerializer):
class Meta:
model = Note
fields = '__all__'

View 集.py

from rest_framework import viewsets

from .models import Note
from .serializer import NoteSerializer

class NoteViewSet(viewsets.ModelViewSet):
queryset = Note.objects.all()
serializer_class = NoteSerializer

url.py

from rest_framework import routers

from .viewsets import NoteViewSet

router = routers.SimpleRouter()
router.register('notes', NoteViewSet)

urlpatterns = router.urls

最佳答案

问题出在 models.py 中,我有一个 FilePathField。

谢谢@IşıkKaplan

from django.db import models

# Create your models here.
class Note(models.Model):
date = models.DateTimeField()
endDate = models.DateTimeField()
note = models.TextField()
attachment = models.CharField(max_length=50)
task = models.BooleanField()
tag = models.CharField(max_length=50)
type = models.CharField(max_length=50)

关于python - 文件未找到错误: [WinError 3] The system cannot find the path specified: '' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57662873/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com