, logi...">

Django view has unexpected keyword argument

I have the following URL pattern:

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

and the corresponding edit_offer view:

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

The link on the proposal page allows you to edit the proposal presentation:

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

clicking on the button raises a TypeError:

 edit_offer() got an unexpected keyword argument 'offer_id' 

Any ideas what is going on? I do not understand what is wrong here. I have other views with similar patterns, and they all work fine.

+8
django
source share
1 answer

Try the following:

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 %} 
+11
source share

All Articles