Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError at / No module named quickstart in django rest framework

Getting error when for tutorial in http://www.django-rest-framework.org/tutorial/quickstart/

error like this:

 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

i have ~/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

and i have ~/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'))
)

i am already installed_apps rest_framework in ~drfdjango/drf/drf/setting.py

    INSTALLED_APPS = (
    ...
    'rest_framework',
)

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

so why ImportError at / No module named quickstart in urls.py line 4?

can you help me solved this problem?

like image 257
point Avatar asked Feb 24 '15 05:02

point


2 Answers

You shouldn't use the drf project name for importing from quickstart app. Import like this:

from quickstart import views
like image 68
catavaran Avatar answered Oct 20 '22 16:10

catavaran


I had the same error and solved it with this line in the urls.py change

from drf.quickstart import views

to

from .quickstart import views
like image 1
Kemar H Avatar answered Oct 20 '22 17:10

Kemar H