http://www.django-rest-framework.org/tutorial/quickstart/中的教程时出现错误

像这样的错误:

 Traceback:
File "/home/apsijogja/drfdjango/end/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  98.                 resolver_match = resolver.resolve(request.path_info)
File "/home/apsijogja/drfdjango/end/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  343.             for pattern in self.url_patterns:
File "/home/apsijogja/drfdjango/end/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  372.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/apsijogja/drfdjango/end/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  366.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/apsijogja/drfdjango/drf/drf/urls.py" in <module>
  4. from drf.quickstart import views

Exception Type: ImportError at /
Exception Value: No module named quickstart

我有〜/drfdjango/drf/quickstart/view.py
    from django.shortcuts import render
from django.contib.auth.models import User, Group
from drf.quickstart.serializers import UserSerializer, GroupSerializer

# Create your views here.

class UserViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited.
    """
    queryset         = User.objects.all()
    serializer_class = UserSerializer

class GroupViewSet(viewsets.ModelViewSet):
    """
    API endpoint that allows users to be viewed or edited
    """
    queryset         = Group.objects.all()
    serializer_class = GroupSerializer

我有〜/drfdjango/drf/drf/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from rest_framework import routers
from drf.quickstart import views

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

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'drf.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)

我已经在〜drfdjango/drf/drf/setting.py中安装了app_restsframework
    INSTALLED_APPS = (
    ...
    'rest_framework',
)

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
    'PAGINATE_BY': 10
}

那么,为什么在urls.py第4行中的/No模块名为quickstart的位置出现ImportError?

您能帮我解决这个问题吗?

最佳答案

drf应用程序导入时,您不应使用quickstart项目名称。像这样导入:

from quickstart import views

关于python - django rest框架中/没有模块名为快速入门的模块上的ImportError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28688556/

10-13 08:44