[Django]-How to pull information saved from IP address call with GeoIP2() django models to display in my html

0๐Ÿ‘

โœ…

I believe I have found the solution. I will post the code first and explain at the bottom.

views.py

    def get(self, request):
    usersession = UserSession.objects.filter(user =self.request.user)
    args = {'usersessions':usersession}
    return render(request, self.template_name, args)

HTML

{% for usersession in in usersessions %}
whatever material you want to loop through
{% endfor %}
  • The HMTL is needs to know how many or which UserSessions to use.So a loop has to be ran for that to get a list of some sort
  • you will need to call on specific object out of the list so in your function in views.py you can set the list (in this case I set it as usersessionS) as args* and then you can get an specific object from the list as well as any info that was stored in there based on your model.
  • I also did a filter on your query so you can get the most recent session as your session.This allows the session that is saved to be the user logged in but i suspect that can be modified to your liking.
๐Ÿ‘คMigdotcom

Leave a comment