Currently working on an exercise from PythonCrashCourse2ndEd. (Ch.18, Ex.8), and i'm getting a SyntaxError: Invalid syntax on urls.py. (line 13 path('pizza/', views.index, name='pizza), I have tried importing the file directly to shell, and it gave me the same error.
urls.py
"""Defines URL patterns for pizzas"""
from django.urls import path
from . import views
app_name = 'pizzas'
urlpatterns = [
#Home page
path('', views.index, name='index')
#Page that shows all the pizzas.
path('pizza/', pizzas.index, name='pizza')
]
views.py
from django.shortcuts import render
from .models import Pizza
def index(request):
"""The home page for pizzas."""
return render(request, 'pizzas/index.html')
def pizzas(request):
"""Show all the pizzas"""
pizzas = Pizza.objects.all()
context = {'pizzas': pizzas}
return render(request, 'pizzas/pizzas.html', context)
pizzas.html
<!--Inherits from base.html-->
{% extends "pizzas/base.html" %}
{% block content %}
<p>Pizzas</p>
<ul>
{% for pizza in pizzas %}
<li>{{ pizza }}</li>
{% empty %}
<li>No pizzas have been added yet.</li>
{% endfor %}
</ul>
{% endblock content %}
Error
>>> import pizzas.urls
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Heyale\OneDrive\Desktop\pizzeria\pizzas\urls.py", line 13
path('pizza/', views.index, name='pizza')
path('', views.index, name='index')...]at end ofurlpatternslist, but I'm guessing that was a cut-and-paste error.