return HttpResponse(output)
and i got this error
'str' object has no attribute 'write'
can anyone help please
Thanks,
Mary
When you do this:
output = ', '.join([m.menu_text for m in latest_menu_list])
you rebound the name 'output' to a string, it no longer references
your file descriptor. Try this:
output_str = ', '.join([m.menu_text for m in latest_menu_list])
output.write(output_str)
In the first line there, you're setting "output" (which used to be a
file object) to a string, and then in the next line you're trying to
call the "write" method again (which would work if it were still a file
object, but it's not anymore).
Do you instead mean this:
output.write(', '.join([m.menu_text for m in latest_menu_list]))
or even:
menulist = ', '.join([m.menu_text for m in latest_menu_list])
output.write(menulist)
Either of those two should work.
-johnnnnnnnn
>i wrote this view
>def index(request):
> output=open( '/var/www/xml-python/xmleditor/test.xml','w')
> output.write('<?xml version="1.0" encoding="iso-8859-1"?>')
> output.write('<content_topnav>')
> latest_menu_list = Menu.objects.all().order_by('-id')
> output = ', '.join([m.menu_text for m in latest_menu_list])
> output.write(output)
>
>
>
> return HttpResponse(output)
>
>
After fixing what others have pointed you will probably have a next
problem with empty output in a browser. You're passing your "output"
object to HttpResponse while output's position is at its end. You should
move to the beginning:
output.seek(0)
return HttpResponse(output)