picomon
picomon

Reputation: 1519

TypeError at /userpage/

I want this code to display list of friends of a user, list of friends to add, after writing the codes and testing it out, I’m getting this error:

     TypeError at /userpage/
        user_page() takes exactly 2 arguments (1 given)
      Request Method:   GET
      Request URL:  http://127.0.0.1:8000/userpage/
      Django Version:   1.3.1
      Exception Type:   TypeError
      Exception Value:  user_page() takes exactly 2 arguments (1 given)
      Exception Location:   C:\Python27\lib\site-packages\django\core\handlers\base.py   in get_response, line 111
     Python Executable: C:\Python27\python.exe
     Python Version:    2.7.2

Below are my codes: Views:

def user_page(request, username):
user=get_object_or_404(User, username=username)
if request.user.is_authenticated():
    is_friend=Friendship.objects.filter(
        from_friend=request.user,
        to_friend=user
        )
else:
    is_friend=False
return render_to_response('user_page.html', context_instance=RequestContext(request))

Template:

    {% extends "base.html" %}

    {% block content %}
      {% ifequal user.username username %}
     <a href="/friends/{{ username }}/">view your friends</a>
    {% else %}
    {% if is_friend %}
      <a href="/friends/{{ user.username }}/">
         {{ username }} is a friend of yours</a> 
    {% else %}
        <a href="/friend/add/?username={{ username }}">
       add {{ username }} to your friends</a> 
     {% endif %}
     - <a href="/friends/{{ username }}/">
       view {{username }}'s friends</a>
   {% endifequal %}
   {% endblock %}

please help me out!

Upvotes: 0

Views: 146

Answers (1)

bouteillebleu
bouteillebleu

Reputation: 2493

The error message is user_page() takes exactly 2 arguments (1 given), which tells you what the problem is - presumably your urlconf expects there to be a username after /userpage/ in the URL, but when there isn't you're still calling user_page() but without a second argument.

Upvotes: 1

Related Questions