FAQ: Creating Your First Django App - Creating a View for an App

This community-built FAQ covers the “Creating a View for an App” exercise from the lesson "Creating Your First Django App ".

Paths and Courses
This exercise can be found in the following Codecademy content:

Build Python Web Apps with Django

FAQs on the exercise Creating a View for an App

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 (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 (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

VIEWS IN DJANGO:
The Django Djitney

I got an error when testing de delete view, in 14.

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):
  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"

urls.py

urlpatterns = [
  path("", views.HomeView.as_view(), name="home"),
  path("lines/", views.LinesView.as_view(), name="lines"),
  path('lines/new/', views.CreateLineView.as_view(), name="create_line"),
  path('lines/<pk>/update/', views.UpdateLineView.as_view(), name="update_line"),
  path("lines/<pk>/delete/", views.DeleteLineView.as_view(), name="delete_line"),
  path("stations/", views.StationsView.as_view(), name="stations")
]

Thanks.

Hey emmanuel 314,

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.

Cheers!