R
R
Roman no_name2014-04-08 17:21:19
Django
Roman no_name, 2014-04-08 17:21:19

HttpResponseRedirect in Django - how to solve the problem?

In general, I faced such a problem. Programming in Python with Django 1.4, I can't find the docs on the HttpResponseRedirect function. The question arose whether it is possible, as in PHP, to redirect to the page and send a message about it when an error occurs.
For example:
I have a database of users who are pulled from the database by id. The user tries to enter a non-existent id and immediately redirects to his page with an error message that there is no such user.
Code example:

@login_required
def show_user_id(request, user_id):
    user = user_id
    for row in django_couch.db().view('users/list_id', key=user).rows:
        return render_to_response('show_users_id.tpl', {
            'user': row})
    else:
        return HttpResponseRedirect('/user/')

All Django hangs on CouchDB. So don't be intimidated by strange requests.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2014-04-08
@Romastr

The redirect will not help you in any way in the output of the error. Use messages framework .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question