Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django view got an unexpected keyword argument

I have a following url pattern:

urlpatterns = pattern('',
    ...
    url(r'edit-offer/(?P<id>\d+)/$', login_required(edit_offer), name='edit_offer'),
)

and a corresponding edit_offer view:

def edit_offer(request, id):
  # do stuff here

a link on offer page leads to edit offer view:

<a class="btn" href="{% url edit_offer offer.id %}">Edit</a>

clicking on the button throws a TypeError:

edit_offer() got an unexpected keyword argument 'offer_id'

Any ideas what is going on? I don't see what's wrong here. I have other views with similar patterns and they all work ok.

like image 418
Neara Avatar asked Nov 18 '12 10:11

Neara


1 Answers

Try this:

Your urls.py:-

urlpatterns = pattern('whatever_your_app.views',
    ...
    url(r'edit-offer/(?P<id>\d+)/$', 'edit_offer', name='edit_offer'),
)

Your views.py:-

from django.contrib.auth.decorators import login_required

...

@login_required
def edit_offer(request, id):
    # do stuff here

and in your template:-

{% url 'edit_offer' offer.id %}
like image 149
Calvin Cheng Avatar answered Sep 28 '22 02:09

Calvin Cheng