You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.

Copyobj=list_benefits()
print obj[0] + " is a benefit of functions!"
print obj[1] + " is a benefit of functions!"
print obj[2] + " is a benefit of functions!"
print obj[3] + " is a benefit of functions!"
Answer from Aswin Murugesh on Stack Overflow
Discussions

python - restframework 'tuple' object has no attribute '_meta' - Stack Overflow
File "/var/www/verinmuebles/current/Env/api/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py" in get_field_info 36. opts = model._meta.concrete_model._meta · Exception Type: AttributeError at /v1/bdetail/ Exception Value: 'tuple' object has no attribute '_meta' More on stackoverflow.com
🌐 stackoverflow.com
February 5, 2017
python - 'tuple' object has no attribute '_meta' - Stack Overflow
why is my queryset throwing this error whenever i make a search to the backend of account object below the post have added the traceback ? def auto_search(request): user = request.user More on stackoverflow.com
🌐 stackoverflow.com
python - AttributeError at / 'tuple' object has no attribute '_meta' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
python - Django error with User form: AttributeError: 'tuple' object has no attribute '_meta' - Stack Overflow
Exception in thread django-main-thread: ... "E:\deep\lib\site-packages\django\forms\models.py", line 181, in fields_for_model opts = model._meta AttributeError: 'tuple' object has no attribute '_meta'... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › carltongibson › django-filter › issues › 1099
_meta error with DRF package. · Issue #1099 · carltongibson/django-filter
July 10, 2019 - UPD. I have an error even if I use filters.FilterSet (for DRF). Remove Meta class is only one way to solve this problem. So if I have a class with two inheritance it will raise an error: AttributeError: 'tuple' object has no attribute '_...
🌐
Stack Overflow
stackoverflow.com › questions › 72095748 › django-error-with-user-form-attributeerror-tuple-object-has-no-attribute-m
python - Django error with User form: AttributeError: 'tuple' object has no attribute '_meta' - Stack Overflow
class CustomUserForm(UserChangeForm): username = forms.CharField( widget=forms.TextInput(attrs={'class': 'form-control my-2', 'placeholder': 'Enter Username'})) email = forms.CharField( widget=forms.TextInput(attrs={'class': 'form-control my-2', 'placeholder': 'Enter The Email'})) password1 = forms.CharField( widget=forms.PasswordInput(attrs={'class': 'form-control my-2', 'placeholder': 'Enter The Password'})) password2 = forms.CharField( widget=forms.PasswordInput(attrs={'class': 'form-control my-2', 'placeholder': 'Confirm Password'})) class Meta: model = User, # Remove this comma because it
Find elsewhere
🌐
GitHub
github.com › translate › pootle › issues › 2400
AttributeError: 'tuple' object has no attribute '_meta' · Issue #2400 · translate/pootle
July 26, 2012 - AttributeError: 'tuple' object has no attribute '_meta'#2400 · Copy link · Assignees · Labels · invalid · Milestone · 2.5 · dwaynebailey · opened · on Jul 26, 2012 · Issue body actions · I go the following traceback when entering a a file in the Terminology project.
Published   Jul 26, 2012
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
🌐
YouTube
youtube.com › roel van de paar
AttributeError: 'tuple' object has no attribute '_meta' error in Django - YouTube
AttributeError: 'tuple' object has no attribute '_meta' error in DjangoHelpful? Please use the *Thanks* button above! Or, thank me via Patreon: https://www.p...
Published   November 22, 2022
Views   69
🌐
Stack Overflow
stackoverflow.com › questions › 43409618 › django-form-attributeerror-tuple-object-has-no-attribute-meta
python - Django form AttributeError: 'tuple' object has no attribute '_meta' - Stack Overflow
It's too late to answer this, but if someone ends up here. I want to share, I too faced the same problem. The issue sometime for this kind of error is a comma somewhere left unintentionally. And as a comma converts a python object to a tuple.
🌐
CopyProgramming
copyprogramming.com › howto › django-error-with-user-form-attributeerror-tuple-object-has-no-attribute-meta
Python: AttributeError in Django User form: 'tuple' object does not have the attribute '_meta'
July 16, 2023 - AttributeError: 'tuple' object has no attribute '_meta' encountered in Django User form error, Django encounters an AttributeError when a 'tuple' object lacks the '_meta' attribute, AttributeError 'tuple' object lacking 'get' attribute causes problem with Django form saving
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-tuple-object-has-no-attribute
AttributeError: 'tuple' object has no attribute X in Python | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'tuple' object has no attribute" occurs when we access an attribute that doesn't exist on a tuple.
Top answer
1 of 4
2

Please do not do serialization yourself: Django has some builtin serializiation functionality, and you can subclass a serializer to change its behavior.

Your view also does not return a HTTP response, but this is a contract it should satisfy (well it should return a HTTP response, or it should raise some error).

Instead you write content to a file, but writing to files is typically not a good idea (unless you expect the filesize to be huge, in which case you can use a temporary file). By using files, you create race conditions, a hacker might also aim to "inject" a different filename and thus overwrting certain files to run arbitrary code, or changing credentials, and finally it is possible that the server has certain permissions making it impossible to write to a file (the permissions of the directory).

Django allows you to see a HTTP response a s a stream object, to which content can be written, like:

from django.http import HttpResponse
from django.core import serializers

def export_categories_json(request):
    response = new HttpResponse(content_type='application/json')
    response['Content-Disposition'] = 'attachment;filename=categories.json'
    serializers.serialize(
        'json',
        Category.objects.all(),
        fields=['name'],
        stream=response
    )
    return response
2 of 4
0

Django's serialization is for models, but you are using .values_list() which returns plain Python lists.

In your specific case, you can simply use the built-in json module:

import json

def export_categories_json(request):

    with open("categories.json", "w") as out:
        values = list(Category.objects.all().values_list('id', 'name'))
        json.dump(values, out)