I have a django project. Some tables with some info already in place.
I can't see the individual data when applying a FOR LOOP
I revised the code. Looked it up and found no apparent mistake.
Can anyone help me?
Views.py:
from django.shortcuts import render
from .models import Client, Address
main_title = 'Company Name'
def home(request):
client_list = Client.objects.all()
address_list = Address.objects.all()
contex = {
'address_list' : address_list,
'main_title' : main_title,
'client_list' : client_list,
}
return render(request, 'home.html', contex)
in home.html
{% for i in address_list %}
<li>{{ i }}</li>
{% endfor %}
And all I see when going in the browser are the bullet points
*
*
The source code in the browser is loading as:
<ul>
<li></li>
<li></li>
</ul>
Now if i change the html code for something without a for loop like
{{ address_list }}
Then the browser shows:
<QuerySet [<Address: THIS IS THE FIRST ADDRESS >, <Address: THIS IS THE SECOND ADDRESS >]>
In other words. The database data is coming trough, But when inside a for loop i gets empty. But I know there are two entries. Because it show two bullet points
EDIT:
After sometime. I striped the code down to the bare minimum and tried to pin-point the problem.
When I finaly figured it out.
my class in the models.py was
class Client(models.Model, RegexValidator):
Once i removed the RegexValidator it worked.
For some stupid reason I tought i had to include RegexValidator in that line.
All solved now