Running into an error in Ch.9


#1

It looks like it might have to be with the way my edit_question is written:

In template /Users/radhigulati/projects/interviewflows/collection/templates/questions/questions_detail.html, error at line 9
Reverse for ‘edit_question’ with arguments ‘()’ and keyword arguments ‘{‘slug’: ‘’}’ not found. 1 pattern(s) tried: [‘questions/(?P[-\w]+)/edit/$’]


#2

Looks like you have a URL generated in your template with an empty slug ({'slug': ''}).

If that doesn’t help, put the code for your url/view/template into pastebin.com and I’ll try to see if I can see the error. :)


#3

All in pastebin! Let me know if there is anything else you need :) Thanks!!

views.py: https://pastebin.com/43rgj2Zs
urls.py: https://pastebin.com/rT5c9uVt
edit_question.html: https://pastebin.com/cwExdbFf
questions_detail: https://pastebin.com/qiGFZP0x


#4

So in questions_detail, you have a piece of code that requires the question and slug to be passed in:

<a href="{% url 'edit_question' slug=question.slug %}">

However, in your view, you’re not passing along the question:

def question_detail(request, slug):
    # grab the object
    question = Questions.objects.get(slug=slug)
    # and pass to the template
    return render(request, 'questions/questions_detail.html', {
    })

So I believe your error is the template being all “ack! I have no question.slug!”

Try passing in the question into the template and see if that fixes things. :)


#5

Oh wow I totally missed that. I don’t think I would have been able to figure that out on my own. Thank you sooooo much!!!