Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attribute error 'function' object has no attribute 'has_header'

Tags:

python

django

i have been encountered by this error

'function' object has no attribute 'has_header'

my url file contans

 url(r'^HighDefs/$', list_HighDefs),

and i have a view defined with the name

list_HighDefs

in views file. I dont know whats wrong.

the view contains

def list_HighDefs(request):
user_logger = Logger()
user_logger.log_stack()


if user_object:
    email = user_object.email
    uname = user_object.first_name+' '+user_object.last_name

    try:
        row = allapps_models.highdef.objects.filter(user_email=email, show_status=1)


    except Exception:

         return error_page(request)

    highdefs = []

    for m in row:
        order_product = int(m.m_id)
        state = m.state

        try:
            category = checkout_models.state.objects.get(pk=product).premature.category.all()
            category = category[0].pk
        except:

            category = 0


        if int(category) == 2:
            if state != 's':
                highdefs.append(m)


    return render_to_response('main/HighDefs.html',{'request': request, 'highdefs': highdefs, 'uname' :uname, 'email': email}, context_instance=RequestContext(request))

else:
    return(login)
like image 320
S.Ali Avatar asked Jan 31 '26 07:01

S.Ali


2 Answers

Your view must return an HttpResponse object.

It does this for one branch of your if statement:

return render_to_response(...)

But not in the else branch.

return(login)

If login is a view function that returns an HttpResponse object, then you can change your return statement to

return login(request)

However, I suspect you want to redirect the user to your login page instead. In that case, change your code to:

from django.http import HttpResponseRedirect
return HttpResponseRedirect('/login/')

where /login/ is the url of your login page.

like image 197
Alasdair Avatar answered Feb 01 '26 19:02

Alasdair


The last line of your view is return login (don't know why you're wrapping your returns in parentheses, it's unnecessary). But presumably login is a function, and you're not calling it. I expect you mean to do return login() or return login(request).

like image 30
Daniel Roseman Avatar answered Feb 01 '26 19:02

Daniel Roseman