Menu
CoddyTech

Projects and Apps

Part of the Django Basics section of Coddy's Django journey. Lesson 4 of 23.

The menu app has a new Opening Hours page in menu/urls.py, but /hours/ answers 404: the project never reads that file.

A Django project is the whole site: mysite/ holds its settings and its main URLconf. An app is one part of the site with its own views and URLs, here menu/. On your computer, python manage.py startapp menu makes one.

The project hands an app part of the address with include():

from django.urls import include, path

urlpatterns = [
    path("shop/", include("shop.urls")),
]

Django matches the start of the address, shop/, then hands the rest to shop/urls.py. Its "cart/" route answers at /shop/cart/. The prefix can be any text, even empty.

challenge icon

Challenge

Easy

In mysite/urls.py, replace the two routes with one route that hands addresses to the menu app's urls.py. / and /about/ keep their addresses.

Press Run: the preview opens /hours/, which says Open every day from 8:00 to 18:00.

Try it yourself

from django.urls import path

from menu import views

urlpatterns = [
    path("", views.home),
    path("about/", views.about),
]

All lessons in Django Basics

Practice on your own: Django playground