Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: ImportError: No module named 'tutorial.quickstart'

I am getting import error even when I am following the tutorial http://www.django-rest-framework.org/tutorial/quickstart/ line by line.

from tutorial.quickstart import views

ImportError: No module named 'tutorial.quickstart'

where my urls.py file looks like

from django.conf.urls import url, include
from rest_framework import routers
from tutorial.quickstart import views

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

urlpatterns = [
        url(r'^', include(router.urls)),
        url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

Note: I have the project in Rest_Tutorial folder which consist of virtual enviroment - env and project tutorial. This tutorial consist of quickstart and tutorial

like image 601
Harshit Goyal Avatar asked Oct 06 '16 07:10

Harshit Goyal


7 Answers

Change from tutorial.quickstart import views to from quickstart import views in both tutorial/url.py file as well as tutorial/quickstart/views.pyfile. This should work.

This is required as python automatically adds your current directory to sys path.

like image 132
Sbk3824 Avatar answered Oct 13 '22 01:10

Sbk3824


Just change tutorial.quickstart import views to from quickstart import views in both tutorial/url.py file as well as tutorial/quickstart/views.py file.

like image 40
karthik k Avatar answered Oct 13 '22 00:10

karthik k


Make sure your tutorial.quickstart is in the same folder as your project. Also make sure it is unzipped ! Otherwise use a absolute path.

Hope it helps !

like image 32
M.Koch Avatar answered Oct 13 '22 01:10

M.Koch


You should use from quickstart import views instead of from tutorial.quickstart import views if you use PyCharm or other IDE. And don't forget change code where use from tutorial.quickstart.[xxx] import [xxx].

like image 40
LiChang Avatar answered Oct 12 '22 23:10

LiChang


In quickstart/views.py: from .serializers import UserSerializer, GroupSerializer in tutorial/urls.py:

from quickstart import views

That worked for me.

like image 26
Dmnc Räthermänn Avatar answered Oct 13 '22 00:10

Dmnc Räthermänn


It works for me by modification tow importing files

  • /tutorial/quickstart/views.py

from tutorial.quickstart.serializers import UserSerializer, GroupSerializer

to

from quickstart.serializers import UserSerializer, GroupSerializer

  • /tutorial/urls.py

from tutorial.quickstart import views

to

from quickstart import views

like image 26
Borin --help Avatar answered Oct 13 '22 01:10

Borin --help


USE:

django-admin startproject tutorial .

INSTEAD of:

django-admin startproject tutorial

while you start the project.

It is mentioned in the documentation.(Read carefully)

like image 23
Aayush Gupta Avatar answered Oct 13 '22 01:10

Aayush Gupta