Django Rest框架快速入门教程错误包含的URLconf 'tutorial.urls'

标签 django django-rest-framework

我尝试完成 https://www.django-rest-framework.org/tutorial/quickstart/ 中的 drf 快速入门教程

使用

Python 3.6.1

django-rest-framework 3.9.4

Django 2.2.1

但是当我运行时

   python manage.py runserver

我收到一个错误

  File "E:\Dropbox\python\drf2\venv\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'tutorial.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

项目结构:

enter image description here

tutorial/urls.py 的内容

from django.urls import include, path
from rest_framework import routers
from tutorial.quickstart import views

router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    path('', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

最佳答案

您的 quickstart 文件夹不会查看 right location 。它应该与 settings.py 处于同一级别。

您可以将quickstart文件夹移动到drf2/tutorial/tutorial,这样就可以解决问题。

注意,您可能错过了 django-admin startproject 教程中的尾随点。

关于Django Rest框架快速入门教程错误包含的URLconf 'tutorial.urls',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56161475/

相关文章:

sql-server - django-pyodbc 与 django-mssql

python - 在 django View 中获取 GET

python - Django REST 框架 : get field of related model in serializer

使用 djoser 进行 Django ninja token 身份验证

python - 使用 django-pipeline 动态压缩静态文件

Django 模型 |获取特定列

python - 更新多对多关系

python - Django REST框架: change field names

python - 如何覆盖 Django Rest Framework Serializer 中的验证?

python - 不调用序列化程序创建函数