Answer the question
In order to leave comments, you need to log in
How to display data from the database?
Is it possible in python to display data on the screen like in php:
print_r($result);
die();
Answer the question
In order to leave comments, you need to log in
If you need it for debugging, then it is better to run django-shell with the python manage.py shell command from the project directory and execute any queries in it. No extra output will bother you and "die()" will not be needed.
You can use the dir() built-in function to get a list of all class attributes. To get the values of an object's attributes, use the built-in vars() function.
from django.contrib.auth.models import User
user = User.objects.first()
vars(user)
{'_password': None,
'_state': <django.db.models.base.ModelState at 0x7871fd0>,
'date_joined': datetime.datetime(2013, 12, 12, 6, 6, 58, tzinfo=<UTC>),
'email': '[email protected]',
'first_name': 'Сергей',
'id': 1,
'is_active': True,
'is_staff': True,
'is_superuser': True,
'last_login': datetime.datetime(2016, 3, 31, 8, 1, 59, 780493, tzinfo=<UTC>),
'last_name': 'Горностаев',
'password': '<secret>',
'username': 'gornostaev'}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question