There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
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):
model = Line
template_name = "routes/lines.html"
class CreateLineView(CreateView):
model = Line
template_name = "routes/add_line.html"
form_class = LineForm
class UpdateLineView(UpdateView):
model = Line
template_name = "routes/update_line.html"
form_class = LineForm
class DeleteLineView(DeleteView):
model = Line
template_name = "routes/delete_line.html"
if you look at 24, you will see that the DeleteView needs a success_url. There is a hint how to implement it for the Stops. If you follow the instructions for the Lines and Stations, these will work and the error does not come up anymore. Hope this helps.