Send data from django to html
Question: I want to get data from database and send that to html page using django-
python.

What I'm doing in python file is

    
    
    def module1(request):
        table_list=student.objects.all()
        context={'table_list' : table_list}    
        return render(request,'index.html',context)
    

And in html is

    
    
    <div class="rightbox">
                In right box. data is :<br> <br>              
           {% if table_list %} 
            <ul> {% for item in table_list %} 
                  <li>{{ item.name }}</li>
                  <li>{{ item.address }}</li>
                  <li>{{ item.mob_no }}</li>
    
                  {% endfor %} 
            </ul> 
           {% else %} 
                <p>somethings is wrong</p> 
            {% endif %}
    
            </div>
    

Nothing is being sent to html file. It is constantly going in else block. I
don't know where I'm making mistake.Please help me.


Answer: So far as we don't see your `student` model (which should be in your
`models.py` and be imported in your `vievs.py`) and your code doesn't throw
any exceptions it seems that your `table_list` is empty. To iterate it in more
convenient way you can use built in `for ... empty` template tag:

    
    
    <div class="rightbox">
        In right box. data is :<br> <br>              
        <ul>
        {% for item in table_list %} 
            <li>{{ item.name }}</li>
            <li>{{ item.address }}</li>
            <li>{{ item.mob_no }}</li>
        {% empty %} 
            <p>somethings is wrong</p>
        {% endfor %} 
        </ul> 
    </div>
    

Try this and see what happens. If you'll find yourself in `{% empty %}` block
- your `table_list` is empty which is points to empty table in database.

Also check
[docs](https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#for-
empty) for this tag.

