我尝试完成 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.
项目结构:
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/