我在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
中安装了appe_framework INSTALLED_APPS = (
...
'rest_framework',
)
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'PAGINATE_BY': 10
}
为什么ImportError在/ no模块中名为quickstart的urls.py第4行?
你帮我解决了这个问题吗?答案 0 :(得分:21)
您不应使用drf
项目名称从quickstart
应用导入。像这样导入:
from quickstart import views
答案 1 :(得分:1)
我遇到了相同的错误,并通过urls.py更改中的这一行解决了该问题
from drf.quickstart import views
到
from .quickstart import views