Polls tutorial: Polls view

I’m stuck. I’m following the Poll tutorial but I get stuck at the start. I can’t see the Polls view. I can follow the tutorial up the polls view. (Python 3.8.2 Django 3.0.6 Windows 10 Home 64 bit

I have to run server on port 8010 and when I run the browser to see the polls I get

command line:
Quit the server with CTRL-BREAK.
Not Found: /polls
[17/May/2020 00:10:33] “GET /polls HTTP/1.1” 404 1954

or (/polls/ vs /polls)

Not Found: /polls/
[17/May/2020 00:28:35] “GET /polls/ HTTP/1.1” 404 1957

browser (Firefox 76.0.1 64bit)

Page not found (404)

Request Method: GET
Request URL: http://localhost:8010/polls/

Using the URLconf defined in mysite.urls , Django tried these URL patterns, in this order:

  1. admin/

The current path, polls/ , didn’t match any of these.

I can’t find the problem and this is the second time I try the tutorial. The first time I got stuck I went to Mozilla to run the tutorial (Django Version 2,1) and I went farther until I got stuck, so I’m coming back to this tutorial.

I have to run on port 8010 because 8005 is still used by the Mozilla tutorial and port 8000 is run by a local file ( I ran Python -m http.server to test it so I can’t use it anymore)

So, how do I free the 8000 port to run new apps? Is this causing my problems?

Any Ideas what should I check?

1 Like

Found my first mistake: I modified the file mysite/urls.py instead of mysite/mysite.py. Also I can use Localhost:8000/polls but localhost:8000 still shows my first test page (a picture)

Please post the contents of your urls.py file - that is where your urls are to be defined. (Include both your mysite/urls.py and your polls/urls.py. There is no mysite/mysite.py file in that tutorial.)

(When posting source code, please include it between lines containing three backticks (`) characters. In other words, you’ll have one line with only ```, then your source code, then another line with ```)

1 Like

Thank you

mysite/urls.py (I got confused. It should be mysite/mysite/urls.py )

This is the code:
‘’’
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path(‘polls/’, include(‘polls.urls’)),
path(‘admin/’, admin.site.urls),
]

‘’’

Ok, so the next two things we need to confirm is your ROOT_URLCONF in your settings is correct, and confirm that you don’t have a different urls.py file in your project that is being referenced.

Assuming your base directory is “mysite”, your ROOT_URLCONF would be ‘mysite.urls’, and you should have a file urls.py in your mysite/polls directory.

Thank you! I finished all the basic tutorials and how to write reusable apps. Any book, class or website besides Django Documents recommended for improving Django skills?

Two Scoops of Django is a great book.

Will Vincent has a lot of good learning materials at LearnDjango and his personal website.

And (shameless plug), I write a lot about Django, podcast about learning the framework, and stream on Twitch regularly to show Django development. mattlayman.com is the place to learn more about what I do.

1 Like

In addition to @mblayman’s answer (with whom I agree 100% on this - those are all excellent suggestions), the awesome-django repository on github has a good list under the Resources section.

There’s another regular here - Adam Johnson, whose blog is worth reading.

In general Python terms, Trey Hunner’s Python Morsels is worth a look. In his blog posts he takes the time to do an in-depth look at different features or characteristics of Python. The morsels are a curated set of exercises to help you really understand what you’re doing with it.

In general, it’s worth following the blogs and other writings of the active people within the Django community.

You could start by looking at the Organizers pages from the last couple of DjangoCons - you’ll see underneath some of the names a “globe” icon, indicating a link to their web sites. It’s also worth looking at the sponsors listing as well - those are the companies that are usually using Django on a regular basis, and may have blogs with django-related materials as well.

Some links to get you started:
https://2019.djangocon.us/organizers/, https://2019.djangocon.us/sponsors/, https://2018.djangocon.us/organizers/, https://2018.djangocon.us/sponsors/,
https://2017.djangocon.us/organizers/, https://2017.djangocon.us/sponsors/

Some of the sponsors are more Django-oriented than others, but most have blogs that contain interesting and/or useful information.

(I’m going to avoid identifying any specific company blogs, because I’ve had the pleasure of meeting a lot of people in this business over the years and really don’t want to insult anyone by forgetting to include them in any list I would post here.)

Ken

How did you end up resolving the error?
I’m stuck in the same place.

1 Like

I solve mine by modifying mysite/mysite/urls.py wich even contain a part of the code to which you just have to add ‘import include…’ and ‘path(‘polls/’…’
… and not mysite/urls.py which is originaly empty of any code.
Hope you succeed!

1 Like

Unfortunately, none of the above answers are clear and effective.

Just open the file “…mysite\mysite\settings.py” and change
ROOT_URLCONF = ‘mysite.urls’
to
ROOT_URLCONF = ‘urls’

1 Like

I have changed the file

var/www/your_account_name_pythonanywhere_com_wsgi.py

this
path = os.path.expanduser(’~/mysite’)

to this
path = os.path.expanduser(’~django_projects/mysite’)

it worked for me

Same for me, I edited the urls.py at the wrong level.

Thank you for posting your reply, I was very stuck.

I have considered all the suggestions, but still, I am facing this problem. I modified the file mysite/mysite/urls.py. But still I am facing this issue and I got stuck

same problem here, im using django 4.0 and i tried every solution but none worked

I suggest you open a new topic with the specifics of the problem you’re encountering. Please include the complete error message you’re receiving.

After a couple agonizing and frustrating hours it worked without any edits to any files. I manually CONTOL-C umpteen times and CMD-R the browser to death and to no avail as something similar seemed to happen previously. I even ps -ax and killed a couple runservers, nada.

I’m leaning towards a browser cache as unlikely as that maybe. But after a few runserver restarts it magically functioned as expected.