Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:23:43+00:00 2026-06-04T13:23:43+00:00

I’m currently working on an application where I want to automatically insert the latitude

  • 0

I’m currently working on an application where I want to automatically insert the latitude and longitude coordinates into a user form. I found a previous post here which aims to do almost exactly what I’m attempting to accomplish geocoding an IP and save using model forms but I seem to be making an error in the process. I’ve installed GeoIP to track the IP and lat, lon from the user.

Here’s the view code:

@login_required
def submit_story(request):
if request.method =="POST":
    story_form = StoryForm(request.POST, request.FILES)
    if story_form.is_valid():
        new_story = story_form.save(ip_address=request.META['REMOTE_ADDR'])
        new_story.author = request.user
        new_story.save()
        return HttpResponseRedirect("/report/all/")
else: # GET request
    story_form = StoryForm()
return render_to_response("report/report.html", {'form': story_form}, context_instance=RequestContext(request))

And this is the form, where I believe the issue lies:

class StoryForm(forms.ModelForm):
    class Meta:
        model = Story
        exclude = ('author','latitude', 'longitude')

    def save(self, ip_address, *args, **kwargs):
        g = GeoIP()
        lat, lon = g.lat_lon(ip_address)
        user_location = super(StoryForm, self).save(commit=False)
        user_location.latitude = lat
        user_location.longitude = lon
        user_location.save(*args, **kwargs)

This is the traceback:

Environment:


Request Method: POST
Request URL: http://localhost:8000/report/report/

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'registration',
 'profiles',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'stentorian.report',
 'south',
 'sorl.thumbnail',
 'gmapi',
 'django.contrib.admin']
Installed Middleware:
 ('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
     File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-        packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
 File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
   23.                 return view_func(request, *args, **kwargs)
 File "/Users/myname/Development/stentorian/../stentorian/report/views.py" in submit_story
  30.             new_story = story_form.save(ip_address=request.META['REMOTE_ADDR'])
 File "/Users/myname/Development/stentorian/../stentorian/report/forms.py" in save
  16.         lat, lon = g.lat_lon(ip_address)

Exception Type: TypeError at /report/report/
Exception Value: 'NoneType' object is not iterable

This is my first time wading into geolocation and first Django project, so I’m quite sure the mistake is simple (perhaps I need to split the tuple, not sure).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:23:44+00:00Added an answer on June 4, 2026 at 1:23 pm

    This

    lat, lon = g.lat_lon(ip_address)
    

    is causing the exception because g.lat_lon() is returning None, so its result
    can’t be unpacked into lat and lon.

    It should return something like (32.0434235, 43.532522) for example.

    This means that you are either passing an invalid argument to g.lat_lon(), or that
    for some other reason it can’t resolve the lat/lon.

    UPDATE:

    new_story = story_form.save(ip_address=request.META['REMOTE_ADDR'])
    

    I suppose you run this from your local workstation and in that case the
    request.META['REMOTE_ADDR'] has the value "127.0.0.1" which obviously
    is not something that g.lat_lon() can resolve.

    When in development the settings.DEBUG == True. So you could do the following

    from django.conf import settings
    
    def submit_story(request):
        remote_addr = request.META['REMOTE_ADDR']
        if settings.DEBUG:
            # We are in debug mode, so we set it to a dummy value.
            remote_addr = 'google.com'
    
        if request.method =="POST":
            story_form = StoryForm(request.POST, request.FILES)
            if story_form.is_valid():
                new_story = story_form.save(ip_address=remote_addr)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.