How to display different contents when refresh every time.

30 views
Skip to first unread message

Chen Xu

unread,
Dec 19, 2013, 4:00:05 PM12/19/13
to django...@googlegroups.com
I am currently working on a web page using Django to recommend people food, basically when people refresh the page, it shows a different food which is from the database. I am wondering if there is a way to show different food every time when people refresh (people dont need to login), does Django provide some sort of session?


Thanks in advance

--
⚡ Chen Xu

Avraham Serour

unread,
Dec 19, 2013, 4:08:41 PM12/19/13
to django...@googlegroups.com
yes, django has session management, but why would you need to do that based on session?
I mean, you could just get a different content every time you render the page, of course showing something in random have a chance of repeating the same, if you have no control on what was already shown to the current person
if you want to be 100% that you won't show the same food for the same person when he reloads the page you would need to store the history and tie that to the user or session.

but in my opinion is not worth the overhead, it is not so bad to have a small % of repeats


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACac-qaKYJfARKv08Y9QUUYW27hLr6a9__K%2BY4EMi-%3D8d-z6Cg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Baker

unread,
Dec 19, 2013, 4:14:05 PM12/19/13
to django...@googlegroups.com
I agree with Avraham, and you can easily accomplish this by using .order_by("?") when using the Django ORM (@see https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.order_by)



For more options, visit https://groups.google.com/groups/opt_out.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Bill Freeman

unread,
Dec 19, 2013, 5:27:50 PM12/19/13
to django-users
If the page is cacheable then, in the wild, all bets are off.


Reply all
Reply to author
Forward
0 new messages