【问题标题】:Django rest framework quickstart tutorial error The included URLconf 'tutorial.urls'Django rest 框架快速入门教程错误 The included URLconf 'tutorial.urls'
【发布时间】:2019-05-16 05:37:11
【问题描述】:

我尝试完成来自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'))
]

【问题讨论】:

  • 你的tutorial/urls.py是什么?
  • @Gasanov 添加到帖子中
  • @JPG 我从教程中复制粘贴它作为最后一次尝试
  • @arpa 如果您想学习该教程,您的项目结构不正确。

标签: django django-rest-framework


【解决方案1】:

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

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

注意,您可能错过了django-admin startproject tutorial . 中的尾随点

【讨论】:

    猜你喜欢
    • 2013-04-10
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 2011-04-18
    • 2023-03-31
    相关资源
    最近更新 更多