Hi all.
I am new to Django, and having major problems with my first app.
I am following both the Django Tutorial (polls app) and the First Django App on w3 Schools. Both are effectively the same idea, with different names for the project & app.
The problem occurs after I add the first view, then configure the urls in both the project and app urls.
I cannot, and I mean I cannot get the localhost:8000/polls/ app to work. I get the image of the rocket on the localhost:8000/ but it never works on the polls/ url.
I have tried over 20 times to set this project up from scratch in the last week, and I have followed the tutorial absolutely to the letter every single time. I would suggest that after trying c23-24 times, this cannot be an input error.
I can also see this issue seems to be common.
can anyone help? If I cant resolve this in the next week or so, I will have to walk away from Django and try a different language.
The error message I get is:
Using the URLConf defined in mysite.urls. django tried these url patterns in this order:
- admin/
The current path, polls/, didnt match any of these.
1 Like
Youâre missing a step somewhere along the way.
First, I suggest you work only from one source - donât try to mix the two.
Please post your project urls.py file, along with your INSTALLED_APPS
setting from your settings.py
Hi, and thanks for replying.
In polls/urls.py I have this:
from django.urls import path
from . import views
urlpatterns = [
path(ââ, views.index, name=âindexâ),
]
and this is in the mysite/urls.py:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path(âpolls/â, include(âpolls.urlsâ)),
path(âadmin/â, admin.site.urls),
]
The tutorial does not ask me to put anything in INSTALLED_APPS yet, however from reading various instances of the same problem, I have tried adding both of the following:
âpollsâ
âpolls.Apps.PollsConfigâ
None of these combinations work.
Thereâs at least one section youâve missed.
Review Step 2, Activating Models.
When you say:
Did that include going back to step 1 and starting from the beginning? Or are you just repeating step 3? If the latter, then I suggest you go back to step 1 and restart.
Hi there.
I havent missed section 2, its just that I havent got that far. The project isnt working on step 1, so I havent yet moved onto step 2.
I have been deleting the entire project and starting from scratch, following the tutorial, and things have broken down at the same point every time.
In terms of the steps I am taking:
1- django-admin startproject mysite
2- cd into mysite
3- python3 manage.py runserver
4- python3 manage.py startapp polls
5- write first view in views.py
6- create urls.py file in polls
7- url path in polls/urls.py
8- url path in mysite/urls.py (this is the inner mysite, not outer)
9- python3 manage.py runserver
And this is where is comes to a halt every time.
The part in the tutorial describes the issue perfectly:
If you get an error page here, check that youâre going to http://localhost:8000/polls/ and not http://localhost:8000/.
The entire problem im having is that there is nothing at localhost:8000/polls/ - its like that url doesnt exist. There is the standard congratulations page at localhost:8000/ - but there is no way of displaying the view from the polls/views.py file.
Iâm sorry, I must have misread your original post. Somehow I got the idea you were on page 3.
Please copy/paste the entire content of your console screen where youâre running runserver
, from the command line containing the runserver
command through the 404
response received from the GET for /polls/
It may also help if you describe your environment in a little more detail. What operating system are you running? What versions of Python and Django are you using? Are you using an IDE for this?
One of the things to check is to ensure you donât have an old copy of runserver still running when youâre trying to run your updated version.
Side note: When posting code here, enclose the code between lines of three backtick - ` characters. That means you will have a line of ```, then your code, then another line of ```. (When posting code from multiple files, itâs generally most useful to do this for each file individually.) This forces the forum software to keep your code properly formatted. This is also the recommended process when posting templates, error messages, and other pre-formatted text.
I am new to Django and Pyhton, and I meet the same problems.
Mybe I got why you canât start your app. You should go to http://localhost:8000/polls/
instead of http://localhost:8000/
You guys seriously need to work out this issue with your tutorial. I have followed the steps EXACTLY, multiple times, and tried starting over from the beginning. I am an experienced developer, and Iâm good at following directions. I have done way more complicated tutorials than this in recent days and been able to navigate them. I
This is the first experience people have with Django, and if they canât even get a basic app working in step 1 of the tutorial, theyâre going to give up and look somewhere else. That is what Iâm about to do. I see that other people are having the same issue and that this still hasnât been addressed, and itâs frustrating.
If you are having an issue with the tutorial and would like assistance, weâre here to help. Please start with identifying exactly what step you are on in the tutorial and what the error is you are encountering.
Yes, Django is very âpickyâ in some regards, and thereâs no getting around that itâs very easy to make mistakes along the way.