Domanda

I'm new with Django and i'm trying to show some data from my db but with no luck. The DB connection is OK and i did syncdb.

I'm trying to iterate on one column of my database (logging) table (handleName)

Model:

class Handle(models.Model):
    handleName = models.CharField(db_column='handleName', max_length=200)

    def __unicode__(self):  # Python 3: def __str__(self):
        return self.handleName 

View:

def logger(request):
    #query_results = Handle.objects.all()
    #return render(request, 'ate_logger/logger.html')

    query_results = Handle.objects.all()
    t = loader.get_template('ate_logger/logger.html')
    c = Context({
        'query_results': query_results,
    })
    return HttpResponse(t.render(c))

Html template:

    {% if query_results %}
        <ul>
        {% for handle in query_results %}
            <li> name {{ handle.handleName }} </li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No data available</p>
    {% endif %}

The problem is that i'm getting No data available but i know for sure i have the data in the db. I've tried to use the tutorial but every thing i do seems OK so maybe someone can suggest a solution?

EDIT-1

I'll try to add some mote information i have a data base with data made by another software, i want to connect with Django to that database and show it's content. as first step i'm trying to iterate on table Handle column idHandle and to show all the values. the problem is that i have no return values in return self.handleName I have tried it also in the manage.py shell and it's also empty.

È stato utile?

Soluzione

Problem is solved by @yuvi help!

Auto modeling the db was the needed option.

docs.djangoproject.com/en/dev/howto/legacy-databases

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top