gpt4 book ai didi

python - Django 无法导入应用程序

转载 作者:行者123 更新时间:2023-11-30 23:00:20 26 4
gpt4 key购买 nike

遵循 django-rest tutorial

应用程序/urls.py:

from django.conf.urls import url, include
from rest_framework import routers
from app.abbr 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 = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

目录结构:

enter image description here

错误:

File "..../app/app/urls.py", line 3, in from app.abbr import views ImportError: No module named 'app.abbr'

所以,叹息......

最佳答案

如果您指出向您展示如何执行此操作的教程,将会很有用。

您不应该从应用程序导入;它指的是包含 urls.py 的内部目录。只需从 abbr 导入即可。

from abbr import views

关于python - Django 无法导入应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35337449/

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