aquaman
aquaman

Reputation: 1658

Error - TypeError got an unexpected keyword argument 'name' in django

I am getting error-

search_user() got an unexpected keyword argument 'name'

my views.py (relevant part)-

    elif 'search_user' in post:
                user = post['user']
                return redirect('search',user)

def search_user(request, user):
    u = user_profile.objects.filter(username = user).first()
    return render(request, 'wall/search_user_page.html', {'user': u, 'username': user})

my urls.py (relevant part)-

url(r'^search_user/(?P<name>\w+)/$', views.search_user, name = 'search'),

and my template -

<input type="text" class="form-control" name="user"/>
                    <button type="submit" name="search_user" class="btn btn-primary btn-default" style="vertical-align: middle">
                        Search
                    </button>

Basically I am taking input , submitting it and searching it from my database but when I click on 'Search' button I get the error.

Help me with this please.

Thanks in advance.

Upvotes: 1

Views: 17632

Answers (1)

catavaran
catavaran

Reputation: 45575

If you use the named parameter in the url then the argument of the view should have the same name.

So change the url to:

url(r'^search_user/(?P<user>\w+)/$', views.search_user, name='search'),

Or change the signature of your view to:

def search_user(request, name):
   ...

Upvotes: 5

Related Questions