You are returning a tuple here:
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Did you forget to add render there perhaps:
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Answer from Martijn Pieters on Stack OverflowYou are returning a tuple here:
elif retailer_pk:
return (request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
Did you forget to add render there perhaps:
elif retailer_pk:
return render(request, 'page-retailer-single.html', {
"products": products,
"sorting": filt["sorting"],
"filtering": filt["filtering"],
"retailer": retailer,
})
There is an extra comma "," at the end of return function in views.py
return render(request, 'index.html',{}), #incorrect
return render(request, 'index.html',{}) #correct
python - Django form saving issue AttributeError 'tuple' object has no attribute 'get' - Stack Overflow
python - AttributeError at / 'tuple' object has no attribute 'get' in Django - Stack Overflow
python - 'tuple' object has no attribute 'get' - Stack Overflow
Django - AttributeError: 'tuple' object has no attribute 'get' [ DRF, Stripe, Python ] - Stack Overflow
Videos
from django.shortcuts import render
from django.http import HttpResponse
import datetime
def home(request):
now=datetime.datetime.now()
context={'datetime_now':now}
return render(request, 'home.html', context)You are not returning a HttpResponse here:
return user_form.errors, restaurant_form.errors
return this instead:
render(request, 'auth/register.html', {'restaurant_form':restaurant_form, 'user_form': user_form})
or rather, you should skip that whole else and return.
Here is your problem:
return user_form.errors, restaurant_form.errors
You returning tuple instead of a response
The clickjacking middleware is calling the response's get method. Hence, your view is not returning a HttpResponse instance.
check the applications views.py file, something is wrong with render or HttpResopose function in return statement. I was getting same error and I was missing render in my return statement.
def relative(request):
return render(request, 'basic_app/relative_url_templates.html')
get_or_create does not just return the object:
Returns a tuple of
(object, created), where object is the retrieved or created object and created is a boolean specifying whether a new object was created.
In your case d has been assigned this tuple instead of the object you expected, so you get the attribute error. You can fix your code by changing it to:
d, created = DiaSemana.objects.get_or_create(dias=diaSemana)
The following two lines look unnecessary to me. The get_or_create call above ensures that d.dias=diaSemana, so there's no need to assign it again. There's probably no need to call save either.
d.dias = diaSemana;
d.save()
instead of this:
dias = models.CharField(max_length=20, choices=DIAS_CHOICES)
do:
dias = models.CharField(max_length=20, choices=DIAS_CHOICES)[0]
as @Alasdair said, the first one in the tuple is the object