I have the project on the production server, and I'm passing certain scripts from a local project to the server one. And it gives me an error that I can't isolate.
ImportError at /
No module named viewsets
Request Method: GET
Request URL: http://sub.domain.com/
Django Version: 1.9.6
Exception Type: ImportError
Exception Value:
No module named viewsets
Exception Location: /home/django/django_project/django_project/urls.py in <module>, line 7
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/django/django_project',
'/home/django',
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Server time: Mié, 11 May 2016 13:12:07 +0200
I have the ViewSet's imported and I don't understand. Since in the other project the API worked perfectly for me.
File urls.py
:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from rest_framework import routers, serializers, viewsets
# API Imports
from .viewsets import BrandViewSet
admin.autodiscover()
# Routers API
router = routers.DefaultRouter()
router.register(r'brand', BrandViewSet)
urlpatterns = patterns('',
# Examples:
url(r'^$', 'app.views.home', name='home'),
# API Rest Framework
url(r'^API', include(router.urls)),
url(r'^admin/', include(admin.site.urls)),
)
Project structure:
/home/django/
|--django_project/
|--django_project/
| |--settings.py
| |--urls.py
| |--wsgi.py
|--my_app/
| |--admin.py
| |--models.py
| |--serializers.py
| |--tests.py
| |--views.py
| |--viewsets.py
|--manage.py
Since tu
urls.py
is outside ofmy_app
, relative import doesn't work, try doing this:Remember that relative import works only within the same module you are in.
For more information on the subject of imports, you can visit the following link:
Let's see: the error says "cannot find module
viewsets
on line 7" , which is this:You have a
.
in front ofviewsets
, which indicates a relative import. I don't think this module is in the same directory asurls.py
, so remove the dot to see if it goes.