DedicatedDreamer
DedicatedDreamer

Reputation: 411

NoReverseMatch at / UpdateView

I try to use an updateview with a form. I get the error:

 Reverse for 'response' with arguments '('',)' not found. 1 pattern(s)
tried: ['app/response/(?P<pk>[-a-zA-Z0-9_]+)/$']

views.py:

class ResponseUpdateView(UpdateView):
    model = Model
    fields = ['response']

urls.py

path( route='response/<slug:pk>/', view=views.ResponseUpdateView.as_view(), name='response' )

template:

   {% extends "base.html" %}     
   {% load crispy_forms_tags %}     
   {% block title %}{% endblock %}     
   {% block content %}
    
   <form method="post" action="{% url 'tower:response' slug %}">
        {% csrf_token %}
        {{ form|crispy }}
        <button type="submit" class="btn btn-primary">Send</button>   </form>
    
    
    {% endblock %}

the error is in the template {% url 'app:response' pk %} specifically pk, I have tried using:

def get_context_data(self, **kwargs):
        context = super(ResponseUpdateView, self).get_context_data(**kwargs)
        context['slug'] = self.kwargs['pk']

together with {% url 'app:response' slug %}

If I don't add the url everything works fine

Upvotes: 0

Views: 83

Answers (1)

Jaap Joris Vens
Jaap Joris Vens

Reputation: 3550

You simply forgot to return the context. The following should work:

def get_context_data(self, **kwargs):
        context = super(ResponseUpdateView, self).get_context_data(**kwargs)
        context['slug'] = self.kwargs['pk']
        return context

Upvotes: 1

Related Questions