If you want this to happen without the user registering and giving you an 
address, you could use a geolocation and ip address database. I think yahoo and 
google both provide these services (I used yahoo because their terms of service 
were less restrictive). If the user allows the browser to report a location, 
use that. Or if not then use the apparent IP address to estimate a time zone. 
Neither are fool proof and in particular a casual user to your site will likely 
be put off by the browser asking to share the location.

hth

- Tom

> On Feb 4, 2019, at 6:04 AM, Mikko Meronen <mikkovillemero...@gmail.com> wrote:
> 
> Hi,
> 
> Thank you for your answer. I tried timezone.now without parentheses, but it 
> gave me server error. I have also tried datetime, but I face the same issue.
> 
> The issue I have:
> I want people to see what happened today in the past. So I created a database 
> where is a story or stories what happened in the history on this day(date). 
> My view should be able to pick a right story from the database based on the 
> users timezone. If Australian visits my webpage at this moment, he should be 
> able to see what happened on February 5 in the past (it's already February 5 
> there). However he sees what happened on February 4, because it is February 4 
> here (in Finland or England, not sure what timezone I'm using). So I want to 
> make my view to understand the end user's local time, so it can pick the 
> right story from the database for the webpage visitor.
> 
> -Mikko
> 
> ma 4. helmik. 2019 klo 10.15 'Amitesh Sahay' via Django users 
> (django-users@googlegroups.com <mailto:django-users@googlegroups.com>) 
> kirjoitti:
> Hello Mikko,
> 
> There are basically two ways which I know . One is the timezone module that 
> you are using another is datetime module. I believe that timezone module is 
> more effective one.
> But instead of calling timezone.now() , call timezone.now.
> 
> Or what is the exact issue are you facing?
> 
> 
> Regards,
> Amitesh Sahay
> 91-750 797 8619
> 
> 
> On Monday, 4 February, 2019, 12:30:07 AM IST, Mikko Meronen 
> <mikkovillemero...@gmail.com <mailto:mikkovillemero...@gmail.com>> wrote:
> 
> 
> Hi,
> 
> Is there any easy way in Django to catch end user's local time when end user 
> access the webpage?
> 
> I have read django documentation and tried to google solutions, but I get 
> quite confused. Below you will find my code. In short the code should show a 
> story on my webpage what happened in the past on the current day. However it 
> doesn't take into account the endusers local time, and thus doesn't work 
> properly.
> 
> 
> Views.py
> from django.utils import timezone
> 
> t = timezone.now()     [This should somehow react to endusers local time]
> dm = t.strftime('%m-%d')
> history = history.objects.filter(monthday__exact=dm)
> historystory = random.sample(list(history), 1)
> args = {'historystory':historystory}
> return render(request, "news/home.html", args)
> 
> home.html
> [in html I have just the basic things to show the content]
> 
> <div class="card">
>             <div class="card-body">
>                 {% for x in historystory %}
>                                   <h4 class="card-text"> {{ x.title }} </h4>
>                                   <h4 class="card-text"> {{ x.subtitle }} 
> </h4>
>                                   <p class="card-text"> {{ x.content }} </p>
>                           {% endfor %}
>               </div>
> </div>
> 
> 
> Settings.py
> LANGUAGE_CODE = 'en-us'
> TIME_ZONE = 'UTC'
> USE_I18N = True
> USE_L10N = True
> USE_TZ = True
> 
> You can check my webpage (http://www.topithenewsdoggy.com/ 
> <http://www.topithenewsdoggy.com/>) to get better understanding what I'm 
> doing. The part is under Additional info.
> 
> -Mikko
> 
> -- 
> 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+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAGD0jj%2Bh_1Pd50eE0e0zXt8P-yozqCnZeYYXTe6bj6Tt6UopxA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> -- 
> 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+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/383150814.2310524.1549268121893%40mail.yahoo.com
>  
> <https://groups.google.com/d/msgid/django-users/383150814.2310524.1549268121893%40mail.yahoo.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> -- 
> 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+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAGD0jjLXV%2BxwMtjE3BSd8aAiVPuePJXLV%2BKaTQZr%2B-78udz4fQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/087559B8-2559-4190-9B79-A5F063903E35%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to