Django Code will not populate for some reason. I have studied the Youtube video at each step and it seems to line up. Do I have a typo?
Link to Exercise:
https://www.codecademy.com/paths/build-python-web-apps-with-django/tracks/views-in-django/modules/django-writing-more-views/projects/the-django-djitney
Link to Solution Video: Django Project The Django Djitney - YouTube
views.py
from django.shortcuts import render
from .models import Line, Station, Stop
from .forms import StopForm, LineForm, StationForm
# Add your imports below:
from django.views.generic import TemplateView, ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
class HomeView(TemplateView):
template_name = "routes/home.html"
def get_context_data(self):
context = super().get_context_data()
context["lines"] = Line.objects.all()
context["stations"] = Station.objects.all()
context["stops"] = Stop.objects.all()
return context
# Create your views here.
class LinesView(ListView):
template_name = "routes/lines.html"
model = Line
# step 8
class CreateLineView(CreateView):
model = Line
template_name = "routes/add_line.html"
form_class = LineForm
# Create View creates a new record in the database using a provided Django form. It handles both GET (displaying the form) and POST(processing the submitted data) requests.
# step 9
class UpdateLineView(UpdateView):
model = Line
template_name = 'routes/update_line.html'
form_class = LineForm
# step 10
class DeleteLineView(DeleteView):
model = Line
template_name = 'routes/delete_line.html'
success_url = "/lines"
# There are files in the routes folder for create, update, and delete.
#step 13
class StationsView(ListView):
model = Station
template_name = 'routes/stations.html'
#step 14
class CreateStationView(CreateView):
template_name = 'routes/add_station.html'
model = Station
form_class = StationForm
# step 15
class UpdateStationView(UpdateView): # name provided by instructions
model = Station # what django Model are we using?
template_name = 'routes/update_station.html' # what template are we using
form_class = StationForm # Which Form Are We Using?
class DeleteStationView(DeleteView): # information provided by instructions
model = Station # what django Model are we using?
template_name = routes/delete_station.html # what template are we using
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
# step 6
path("lines/", views.LinesView.as_view(), name= "lines"),
# step 7
path('lines/new/', views.CreateLineView.as_view(), name= 'create_line'),
# step 8
path('lines/<pk>/update/', views.UpdateLineView.as_view(), name='update_line'),
# step 10
path('lines/<pk>/delete', views.DeleteLineView.as_view(), name='delete_line'),
# in the name = field you need to go to the respective .html file and search for the href
#step 13
path('stations/', views.StationsView.as_view(), name='stations'),
#step 14
path('stations/new/', views.CreateStationView.as_view(), name='create_station'),
#step 15
path('stations/<pk>/update', views.UpdateStationView.as_view(), name='update_station'),
# in the name = field you need to go to the respective .html file and search for the href
path('stations/<pk>/delete/', views.DeleteStationView.as_view(), name='delete_station'),
# in the name = field you need to go to the respective .html file and search for the href
path('stations/<pk>/delete/', views.DeleteStationView.as_view(), name='delete_stations'),
models.py
from django.db import models
class Line(models.Model):
name = models.CharField(unique=True, max_length=200)
def get_absolute_url(self):
return "/lines"
def __str__(self):
return f"{self.name}"
class Station(models.Model):
name = models.CharField(unique=True, max_length=200)
accessible = models.BooleanField(default=False)
def get_absolute_url(self):
return "/stations"
def __str__(self):
return f"{self.name}{' (♿)' if self.accessible else ''}"
class Stop(models.Model):
# The snippet of code below ensures that no line can have two stops with the same stop number
class Meta:
unique_together = (('line', 'stop_number'))
def get_absolute_url(self):