0

I am new to using Django and following a tutorial (https://video.cs50.io/w8q0C-C1js4?screen=gytX_rSwZRQ&start=1160).

So far this course has been great! However, now I am stuck at successfully creating a new app using Django.

Here is the result of my efforts: [Lecture3 Page not found

Here is what the result should be: Hello, World page when found tutorial

As far as I know I've done everything correctly, perhaps I am missing something?

Below is the code I am using, which results in Django returning the error in the title:

urls.py lecture3:

    from django.contrib import admin
    from django.urls import include, path

    urlpatterns = [
    path('admin/', admin.site.urls),
    path('hello/', include("hello.urls"))
    ]

urls.py hello:

    from django.urls import path

    from . import views

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

views.py:

    from django.http import HttpResponse
    from django.shortcuts import render

    # Create your views here.
    def index(request):
    return HttpResponse("Hello, World!")

settings.py:

    INSTALLED_APPS = [
    'hello',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ]

I am currently using: Python 3.9.4, and Django 3.2.3

Any and all help that can be provided will be greatly appreciated.

Thanks in advance, Richardson

  • 1
    What's attempttwo here?? Just check settings file where url conf is pointing too? – Ashish Nautiyal Jun 18 '21 at 17:04
  • @AshishNautiyal Thanks for the response. Attemptwo is the name I gave to my previous attempt at starting the app. I've since renamed it lecture3 for convenience. I checked the settings file as you suggested and this is what is there: INSTALLED_APPS = [ 'hello', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] ROOT_URLCONF = 'lecture3.urls' Among other lines of code provided by Django – Richardson Jun 18 '21 at 19:23
  • I think somehow somewhere left some reference to old Attempttwo as from error page it's still referencing to previous urlconf.please go through these links and cross check if any old reference is still there...https://stackoverflow.com/questions/18293875/easy-way-to-rename-a-django-project and https://stackoverflow.com/questions/8408046/how-to-change-the-name-of-a-django-app – Ashish Nautiyal Jun 19 '21 at 05:52

2 Answers2

0

The issue is coming from ‘attempttwo.urls’ so revise your settings file.

Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13
  • Thanks for your advice @Mohamed Elkalioby, I accidentally snipped my previous effort where "attempttwo.urls" comes from. I've edited the post and it now includes my current effort named lecture3. Is the problem still the same? If so, do you know what needs to be changed on the settings file? – Richardson Jun 18 '21 at 17:12
  • Move hello to the bottom of INSTALLED_APPS, and try again, don’t expect it to work – Mohamed ElKalioby Jun 18 '21 at 20:13
  • I tried what you suggested, as you can see: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'hello', ] But as you predicted, it didn't work. I guess I'll have to look for an alternative. Thanks again for the advice! – Richardson Jun 18 '21 at 22:05
  • Try to downgrade Django and see if it will works. – Mohamed ElKalioby Jun 19 '21 at 06:59
0

the path you provided is path('hello/', include("hello.urls")) you need to add "/hello" at the end of the url in the browser, when you run python3 manage.py runserver.

hammad
  • 1