2014-10-08 17 views
15

Tôi có chế độ xem đơn giản sau đây. Tại sao nó dẫn đến lỗi này?Chế độ xem không trả lại đối tượng HttpResponse. Nó trả về Không thay thế

The view auth_lifecycle.views.user_profile didn't return an HttpResponse object. It returned None instead.

"""Renders web pages for the user-authentication-lifecycle project.""" 
from django.shortcuts    import render 
from django.template    import RequestContext 
from django.contrib.auth   import authenticate, login 

def user_profile(request): 
    """Displays information unique to the logged-in user.""" 

    user = authenticate(username='superuserusername', password='sueruserpassword') 
    login(request, user) 

    render(request, 'auth_lifecycle/user_profile.html', 
      context_instance=RequestContext(request)) 

Trả lời

40

Bởi vì quan điểm phải trởrender, không chỉ gọi nó. Thay đổi dòng cuối cùng để

return render(request, 'auth_lifecycle/user_profile.html', 
      context_instance=RequestContext(request)) 
2

tôi đã có lỗi tương tự sử dụng một UpdateView

Tôi có điều này:

if form.is_valid() and form2.is_valid(): 
    form.save() 
    form2.save() 
    return HttpResponseRedirect(self.get_success_url()) 

và tôi giải quyết chỉ thực hiện:

if form.is_valid() and form2.is_valid(): 
    form.save() 
    form2.save() 
    return HttpResponseRedirect(reverse_lazy('adopcion:solicitud_listar')) 
Các vấn đề liên quan