Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGreg Kaleka
39,021 PointsCode Challenge: Updating Django Template to Include Delete Form
On Step 2, I'm getting an error "Didn't find the form" from the challenge. I'm not sure what I'm doing wrong...
In the code below, everything below {{ article.body|linebreaks }}
is code I added for this challenge.
<h1>{{ article.title }}</h1>
<p>By: {{ article.author }}</p>
{{ article.body|linebreaks }}
<hr>
<form action="" method="post">{% csrf_token %}
<input type="submit" value="Delete Article" />
</form>
Here's the code you need to pass the first challenge:
from django.views import generic
from . import models
class ArticleList(generic.ListView):
model = models.Article
class ArticleDetail(generic.DeleteView, generic.DetailView):
model = models.Article
template_name = "articles/article_detail.html"
class ArticleCreate(generic.CreateView):
fields = ('title', 'body', 'author', 'published')
model = models.Article
class ArticleUpdate(generic.UpdateView):
fields = ('title', 'body', 'author', 'published')
model = models.Article
class ArticleDelete(generic.DeleteView):
model = models.Article
class ArticleSearch(generic.ListView):
model = models.Article
def get_queryset(self):
qs = super().get_queryset()
term = self.kwargs.get('term')
if term:
return qs.filter(body__icontains=term)
return qs.none()
1 Answer
Ryan S
27,276 PointsHi Greg,
There are basically 2 reasons why your code isn't passing. The first is that you will need to include the actual form after the csrf token.
The second has to do with the challenge being really picky on the template code. It is expecting a really basic form element but you've added in a couple extra things like the action attribute and a submit button, which the challenge doesn't seem to like.
The following code is a trimmed down version of yours, with the addition of the form itself, and it should pass.
<form method="post">
{% csrf_token %}
{{ form }}
</form>
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsGoodness... Even including the
action=""
is too much for it hah.Thanks for your help!!
Ryan S
27,276 PointsRyan S
27,276 PointsNo problem. And yeah I was surprised by this too, especially since Kenneth tends to build out the forms a little more in the videos. I would have thought the challenge would be a little more forgiving.