2014-10-08 1 views
15

다음과 같은 간단한보기가 있습니다. 왜이 오류가 발생합니까?뷰가 HttpResponse 객체를 반환하지 않았습니다. 대신 None을 반환했습니다.

"""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)) 

답변

40

보기가 반환render, 그냥 전화하지해야하기 때문에

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

.

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

에 마지막 줄을 변경 나는이 가지고 있던 UpdateView

사용하여 동일한 오류가 발생했습니다 :

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

을하고 난 그냥 일을 해결했다 :

if form.is_valid() and form2.is_valid(): 
    form.save() 
    form2.save() 
    return HttpResponseRedirect(reverse_lazy('adopcion:solicitud_listar')) 
관련 문제