Home Top Ad

Django telling me template doesn´t exist

Share:

Django telling me template doesn´t exist

Can anybody tell me why django is telling me that template does not exist? I would like to go from the film_detail.html to film_report.html, when clicking on the "report"-button...
views.py
class FilmReport(LoginRequiredMixin, UpdateView):
    model = Report
    fields = ["comment", "reporter", "reports"]
    # def __str__(self):
    #     return self.title

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)
urls.py
app_name = 'watchlist'

urlpatterns = [
    path("", views.films_view, name="board-home"),
    path("film/add", FilmAddView.as_view(), name="film-add"),
    path("film/<int:pk>/", FilmDetailView.as_view(), name="film-detail"),
    path("film/<int:pk>/report", FilmReport.as_view(), name="film-report")
]
film_detail.html
{% extends "board/base.html" %}
{% block content %}
<article class="media content-section">
  <img class="rounded-circle film-img" src="/media/{{object.poster}}">
  <!-- Mulighet for å ha en "add review"-knapp på siden der hvor filmene vises. -->
  <a href=" {% url 'watchlist:film-add' %}" class="waves-effect waves-light green btn"><i class="material-icons right">rate_review</i>add review</a>
  <a href=" {% url 'watchlist:film-report' film.id%}" class="waves-effect waves-light red darken-4 btn"><i class="material-icons right">report</i>report</a>

    <div class="media-body">
      <h2 class="film-title">{{ object.title }}</h2>
      <p class="film-plot">{{ object.plot }}</p>
    </div>
  </article>
{% endblock content %}
film_report.html
{% extends "board/base.html" %}
{% block content %}
<h2>Film report</h2>
<!-- <article class="media content-section">
  <img class="rounded-circle film-img" src="/media/{{object.poster}}">

    <div class="media-body">
      <h2 class="film-title">{{ object.title }}</h2>
    </div>
  </article> -->
{% endblock content %}
You didn't specify template name for your FilmReport class, so django assumed default name. Default name for UpdateView is <model_name>_form.html.
It's not the issue with FilmDetailView, because it's subclassed from DetailView, which is default to <model_name>_detail.html.
Either change name of your template from film_report.html to report_form.html or template_name='film_report.html' in FilmReport. Here's example from django docs and here's more in details about how it works.

Aucun commentaire