Django - 无法构建 API
Django - unable to build API
好吧,我正在尝试访问“http:// 127.0.0.1:8000/api/files/”,但出错了,即:
Using the URLconf defined in WTF_2.urls, Django tried these URL patterns, in this order:
admin/
graphql/
Start/
The current path, api/file/, didn’t match any of these.
我明白这是怎么回事,但实在找不到我哪里做错了。
我的 'File' 模型来自 'Start/models.py:
class File(models.Model):
class Meta:
ordering = ['-publish_date']
title = models.CharField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True)
...
...
我的 'urls.py' 来自 'Start/urls.py':
from django.urls import path
from .views import FileView
app_name = 'Start'
urlpatterns = [
path('Start/', FileView.as_view()),
]
还有我的 'urls.py' 来自 'mainproject/urls.py':
from django.contrib import admin
from django.urls import path, include
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
urlpatterns = [
path('admin/', admin.site.urls),
# graphiql = true указывает графену сделать доступным graphiql интерфейс
path('graphql', csrf_exempt(GraphQLView.as_view(graphiql=True))),
# api интерфейс
path('Start/', include('Start.urls'))
]
您似乎在某个时候调用了 url api/file
,但是您的 urls.py 文件没有将其作为路径。
您应该考虑将适当的 api/file
url 和相关视图添加到您的 urls.py
。
好吧,我正在尝试访问“http:// 127.0.0.1:8000/api/files/”,但出错了,即:
Using the URLconf defined in WTF_2.urls, Django tried these URL patterns, in this order:
admin/
graphql/
Start/
The current path, api/file/, didn’t match any of these.
我明白这是怎么回事,但实在找不到我哪里做错了。 我的 'File' 模型来自 'Start/models.py:
class File(models.Model):
class Meta:
ordering = ['-publish_date']
title = models.CharField(max_length=255, unique=True)
slug = models.SlugField(max_length=255, unique=True)
...
...
我的 'urls.py' 来自 'Start/urls.py':
from django.urls import path
from .views import FileView
app_name = 'Start'
urlpatterns = [
path('Start/', FileView.as_view()),
]
还有我的 'urls.py' 来自 'mainproject/urls.py':
from django.contrib import admin
from django.urls import path, include
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
urlpatterns = [
path('admin/', admin.site.urls),
# graphiql = true указывает графену сделать доступным graphiql интерфейс
path('graphql', csrf_exempt(GraphQLView.as_view(graphiql=True))),
# api интерфейс
path('Start/', include('Start.urls'))
]
您似乎在某个时候调用了 url api/file
,但是您的 urls.py 文件没有将其作为路径。
您应该考虑将适当的 api/file
url 和相关视图添加到您的 urls.py
。