2
As soon as I click on a button that calls my view to edit the Row of the table in question shows me the error: 'Meumodel' Object is not iterable.
- I’m using Django 2.1.15
- Python 3.8.1
- SQL server database
py views.
def Alterar_Pessoa(request, id):
visitantes = get_object_or_404(DadosPessoas, pk=id)
form = PessoaForm(instance=visitantes)
if(request.method == 'POST'):
return False
else:
return render(request, 'portaria/cadastroPessoa.html', {'form': form, 'visitantes': visitantes})
Full error message:
TypeError at /portaria/alterarPessoa/18
'DadosPessoas' object is not iterable
Request Method: GET
Request URL: http://127.0.0.1:8000/portaria/alterarPessoa/18
Django Version: 2.1.15
Exception Type: TypeError
Exception Value:
'DadosPessoas' object is not iterable
Exception Location: C:\Users\leona\AppData\Roaming\Python\Python38\site-packages\django\template\defaulttags.py in render, line 165
Python Executable: C:\Users\leona\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version: 3.8.1
Python Path:
['C:\\Users\\leona\\OneDrive\\Ambiente de '
'Trabalho\\projeto\\MCS_JSP\\mcs\\MCS_Back',
'C:\\Users\\leona\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\leona\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\leona\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\leona\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\leona\\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\leona\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Server time: Sex, 10 Abr 2020 13:21:14 -0300
Error during template rendering
In template C:\Users\leona\OneDrive\Ambiente de Trabalho\projeto\MCS_JSP\mcs\MCS_Back\portaria\templates\portaria\cadastroPessoa.html, error at line 372
Linha 372: {% for visitante in visitantes %}
puts the complete error message and the line where it is accusing error
– Savrige
I added the message and the line
– Leonardo Monsuete
this error accuses that the visitors variable is not eternal, that is, python cannot run for loop on it. What is the type of visitor data? run a print(type(visitors))
– Savrige