Django Djitney Project, stop form not found

I’ve finished coding for the Django Djitney project. I’m finding that the Lines and Stations functionality all works as expected. When I try to select any option with stops, I get an error message such as:

# TemplateDoesNotExist at /stops/1/update

routes/stop_form.html

|Request Method:|GET|
| --- | --- |
|Request URL:|http://e516eba060c943f49396605ef5820830.cc-propeller.cloud/stops/1/update|
|Django Version:|3.1.4|
|Exception Type:|TemplateDoesNotExist|
|Exception Value:|routes/stop_form.html|
|Exception Location:|/usr/local/lib/python3.6/dist-packages/django/template/loader.py, line 47, in select_template|
|Python Executable:|/usr/bin/python3|
|Python Version:|3.6.9|
|Python Path:|['/home/ccuser/workspace/django-djitney-project', '/var/codecademy/runner_contexts/python', '/home/ccuser/workspace/django-djitney-project', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']|
|Server time:|Sun, 22 May 2022 01:10:05 +0000|

We definitely don’t have the stop_form.html in the routes folder, but the request isn’t even for localhost. Here is my code for updating the stop.

views.py

class UpdateStopView(UpdateView):
  model = Stop
  template = "routes/update_stop.html"
  form_class = StopForm

urls.py

path("stops/<pk>/update", views.UpdateStopView.as_view(), name="update_stop"),

This is identical to how Line and Station look, and both of those are working. Is there something I’m missing here?

Without seeing the entire project, it’s difficult to say… but the UpdateStopView class looks as I would have expected it to, as does the URL entry.

I notice that you edited your post, though annoyingly I can’t see the previous edit, but I’m wondering whether you noticed and corrected your own error after posting?

In any event, from the code you’ve posted I can’t see anything immediately wrong.

The issue is in the following block:

class UpdateStopView(UpdateView):
  model = Stop
  template = "routes/update_stop.html"
  form_class = StopForm

The parameter name for the template should be “template_name.” Hence, the block here should be:

class UpdateStopView(UpdateView):
  model = Stop
  template_name = "routes/update_stop.html"
  form_class = StopForm
1 Like