Same tutorial different day

203 views
Skip to first unread message

kit...@gmail.com

unread,
Jun 5, 2017, 9:51:18 PM6/5/17
to Django users
I was attempting the tutorial titled "Writing your first Django app".  The tutorial appears to be very simple, but it does not seem to work.  I have frustrated myself by attempting to do it from scratch after failing last week.  If I could get this app to work I could fix the tutorial for you.  It looks like a lot of people have similar gripes about the directions not working.

I get errors like ModuleNotFoundError: No module named 'polls'

my directory structure looks like this : 

/home/me/parent/mysite/
                                       db.sqlite3
                                       manage.py
                                       mysite/

/home/me/parent/mysite/mysite/
                                                   __init__.py
                                                   polls/
                                                   settings.py
                                                   urls.py
                                                   wsgi.py

the content of urls.py is : 

from django.conf.urls import include, url

from django.contrib import admin


urlpatterns = [

    url(r'^polls/', include('polls.urls')),

    url(r'^admin/', admin.site.urls),

]


/home/me/parent/mysite/mysite/polls/
                                                           __init__.py
                                                           admin.py
                                                           apps.py
                                                           migrations
                                                           models.py
                                                           tests.py
                                                           urls.py
                                                           views.py
                                                          
the content of urls.py is : 

from django.conf.urls  import url


from . import views


urlpatterns = [

    url(r'^$', views.index, name='index'),

]




the content of views.py is : 


from django.shortcuts import render

from django.http import HttpResponse



# Create your views here.


def index(request):

    return HttpResponse("Hello, Mothers Fuckers!  You're at the polls index!")



So can somebody please tell me why I get ModuleNotFoundError: No module named 'polls'.



Lachlan Musicman

unread,
Jun 5, 2017, 10:28:16 PM6/5/17
to django...@googlegroups.com
I think your mysite/urls.py needs an

import polls



------
"Mission Statement: To provide hope and inspiration for collective action, to build collective power, to achieve collective transformation, rooted in grief and rage but pointed towards vision and dreams."

 - Patrisse Cullors, Black Lives Matter founder

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/09c07d79-bcbf-4451-9d73-9d7189e66dfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Schneider

unread,
Jun 5, 2017, 10:31:16 PM6/5/17
to django...@googlegroups.com


On Jun 5, 2017 6:50 PM, <kit...@gmail.com> wrote:
I was attempting the tutorial titled "Writing your first Django app".  The tutorial appears to be very simple, but it does not seem to work.  I have frustrated myself by attempting to do it from scratch after failing last week.  If I could get this app to work I could fix the tutorial for you.  It looks like a lot of people have similar gripes about the directions not working.

I get errors like ModuleNotFoundError: No module named 'polls'

In most cases, this error is a result of missing the INSTALLED_APPS setting change here:

Note that Django has an active community and that any errors in the tutorial would likely be flagged and fixed quickly. 

I would like to see a 'common mistakes and errors' section added to the tutorial for troubleshooting help.


# Create your views here.


def index(request):

    return HttpResponse("Hello, Mothers F


Please be cognizant of the code you are copying to a public list in the future.

-James

James Schneider

unread,
Jun 5, 2017, 10:35:29 PM6/5/17
to django...@googlegroups.com


On Jun 5, 2017 7:27 PM, "Lachlan Musicman" <dat...@gmail.com> wrote:
I think your mysite/urls.py needs an

import polls

Ah, yes. This is the other common issue with the tutorial. Many of the code blocks omit the necessary import statements to keep the examples easier to read. The expectation is that the reader has at least a basic understanding of Python and how it references other libraries. Admittedly, they are easy to forget.

-James

Jani Tiainen

unread,
Jun 6, 2017, 6:01:49 AM6/6/17
to django...@googlegroups.com

Hi,

If you feel that Django official tutorial isn't verbose enough, you could try out Django Girls tutorial [1]


[1] https://tutorial.djangogirls.org/en/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

-- 
Jani Tiainen

knbk

unread,
Jun 6, 2017, 7:22:42 AM6/6/17
to Django users
You should move the `polls/` subdirectory to the outer `mysite/` directory, rather than the inner `mysite/mysite/` directory. The tutorial does actually say this, but admittedly it's easy to miss:

Your apps can live anywhere on your Python path. In this tutorial, we’ll create our poll app right next to your manage.py file so that it can be imported as its own top-level module, rather than a submodule of mysite.

 You don't need to `import polls` in your urls.py, since it doesn't actually use the `polls` module, it only has a string reference to that module. Django takes care of importing whatever you pass to `include()` if it's a string reference. 

Melvyn Sopacua

unread,
Jun 6, 2017, 8:07:28 AM6/6/17
to django...@googlegroups.com

On Monday 05 June 2017 11:24:08 kit...@gmail.com wrote:

> I was attempting the tutorial titled "Writing your first Django app".

> The tutorial appears to be very simple, but it does not seem to work.

> I have frustrated myself by attempting to do it from scratch after

> failing last week. If I could get this app to work I could fix the

> tutorial for you. It looks like a lot of people have similar gripes

> about the directions not working.

 

You went into parent/mysite/mysite/ then created polls there. That shouldn't even work, because there is no manage.py inside parent/mysite/mysite/. So you adapted and went further down the rabbit hole.

The tutorial clearly states:

 

"In this tutorial, we’ll create our poll app right next to your manage.py file so that it can be imported as its own top-level module, rather than a submodule of mysite.

To create your app, make sure you’re in the same directory as manage.py and type this command"

So two times it's pointing you to the right directory.

 

> /home/me/parent/mysite/mysite/

> __init__.py

> polls/

 

And if you don't, you end up with polls in the wrong place.

 

For the people who answered "import polls", it's wrong and only aggrevates the issue (poll does not have the correct name in polls.apps.PollsConfig for django to find it's models). On top of that, polls.urls is referenced by string, so importing won't fix a thing.

 

The tutoral could probably be improved by listing the complete tree after creating polls app, showing mysite as sister directory, but honestly, it told you exactly what to do twice.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages