[Django]-Django Manual Debugging Process Flow

4👍

If that’s really your view code, it’s a simple indentation error. It should be:

def user_profile(request):
    if request.method=='POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/loggedin')
    else:
        user = request.user
        profile = user.profile
        form = UserProfileForm(instance=profile)

    args = {}
    args.update(csrf(request)) // security token
    args['form'] = form
    return render_to_response('profile.html', args)

What’s going on is that when request.METHOD is GET, there’s no else clause on the initial if, so the view function ends without returning anything. Instead, you want to create the form, add it to the context, and render it – either because it’s a GET request or because there were errors in the form, and you want to rerender the context to show those errors and allow the user to correct them.

Leave a comment