[Answer]-Search user by username and redirect to the user page in Django

1👍

You can’t pass the result of a form in the URL. The form will send it as part of the GET or POST variables, so your view needs to get it from there rather than from a URL parameter.

So, your view needs to be:

def user_by_id(request):
    uid = request.GET['uid']
    ...etc...

and your urls.py is

url(r'^user_by_id/$', user_by_id, name="user_by_id")

and your form is:

<form action="{% url 'user_by_id' %}" method="GET">

(note I’ve changed the method from POST to GET, because you’re not changing information in the database, you’re simply requesting to view something).

Leave a comment