Forums

Page not found (/admin, /polls) - following tutorial

Hi! After running into problem with my first try I completely deleted the installation and started blank. But, once again, I am running into problems: "Page not found" for the /admin and /polls subpages. My 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), ]

polls/urls.py

from django.urls import path
from . import views

urlpatterns = [ path('', views.index, name='index'), ]

and btw, here I get an error for the "from . import":

Traceback (most recent call last): File "/home/magus/django_projects/mysite/polls/urls.py", line 3, in <module> from . import views ImportError: attempted relative import with no known parent package

I went back and through all steps multiple times but I cannot figure out what I did wrong!

Please help me. Thanks.

are you sure that's the most recent error you are seeing from your error log?

I tried some things today, especially regarding this import error message which I could remove though I am not quite sure how. I tried
from polls import views -> error.
import views -> error
Then I reran python3 manage.py check && python3 manage.py migrate && python3 manage.py makemigrations and changed it back to
from . import views
-> no more error in the console.

My error log show NO errors as of today.

But I still the admin and polls pages could not be found. 404 error in the access log. And my "root page" is this :

Hello, World!

This is the default welcome page for a PythonAnywhere hosted web application.

Find out more about how to configure your own web application by visiting the web app setup page

seems like you dont have urls.py setup correctly then.

also be sure to reload your PythonAnywhere webapp after you make changes

Thanks. Mmh. That's what I think too since all routing get's done through the urls.py files. As far as I got it.

Let's see: My 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),
]

polls/urls.py

from django.urls import path
from . import views

urlpatterns = [
path('', views.index, name='index'),
]

If I compare these with the tutorial it is identical.

Btw, I use Python 3.6.9 and Django 3.0.9 within a virtual environments. (I follow along Dr. Chicks course on Coursera)

Are there any config files that I need to check that influence if I get to see the page?

And the first part of my settings.py look like this:

import os. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

SECRET_KEY = **
DEBUG = True

ALLOWED_HOSTS = [ '*' ]
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

You're not actually running your Django code at all in your web app. You're still running the default WSGI file. We have a help page for that here Pay particular attention to the parts involving your WSGI file.

Hi! Many Thanks. This did it. I changed the wrong wsgi file. :-(
As a feedback from a beginner:
it is a little bit confusing to say the least if you get asked to change WGSI Configuration File naturally I thought it must be the file in /home/username/django_projects/mysite/mysite It never occurred to me that there might be a different config file :-(

Thanks!!

OK, glad to hear that you got there in the end! Which tutorial were you following?

This tutorial https://docs.djangoproject.com/en/3.0/intro/tutorial01/ in combination with the Coursera course run by Dr. Chuck.

Ah, I see -- thanks!

I am still confuse about this. I have made sure my code is right. but still get page not found.

You get a "page not found" error when you have not defined a url for the path that you're trying to access. So make sure that you have a URL defined for the path that you're using.