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

  • Home
  • SEARCH
  • 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 7576609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:57:51+00:00 2026-05-30T16:57:51+00:00

I want to test the Google Maps Static API with Django 1.3 (using Python

  • 0

I want to test the Google Maps Static API with Django 1.3 (using Python 2.7). For this purpose, I have created a simple form for querying the coordinates (latitude & longitude), the zoom level, and the map size. The form looks like this:

from django import forms

class GoogleMapsStaticApiForm(forms.Form):
    latitude = forms.FloatField(required=True, min_value=-90.0, max_value=90.0)
    longitude = forms.FloatField(required=True, min_value=-180.0,max_value=180.0)
    zoom_level = forms.IntegerField(required=True, min_value=0, max_value=21)
    map_width = forms.IntegerField(required=True, min_value=0, max_value=640)
    map_height = forms.IntegerField(required=True, min_value=0, max_value=640)

In the respective view, I want to build the URL from the information given in the form and return the URL to a template which should render the map in the same template.

The view:

def map_properties(request):
    map_url = 'http://maps.google.com/maps/api/staticmap?'

    if request.method == 'POST':
        form = GoogleMapsStaticApiForm(request.POST)
        if form.is_valid(): 
            center = 'center={0},{1}'.format(form.latitude, form.longitude)
            zoom = 'zoom={0}'.format(form.zoom_level)
            size = 'size={0}x{1}'.format(form.map_width, form.map_height)
            url_suffix = '&'.join((center, zoom, size, 'sensor=false'))
            map_url = ''.join((map_url, url_suffix))
    else:
        form = GoogleMapsStaticApiForm()

    return render_to_response('frontend/frontend.html', 
                          {'form':form, 'map_url':map_url},
                          context_instance=RequestContext(request))

The template:

<html>
    <head>
        <title>Google Maps Static API - Demo</title>
    </head>
    <body>

        <form method="post" accept-charset="UTF-8">
            {% csrf_token %}

            {% for field in form %}
                <input type="text" placeholder={{ field.html_name }}>
            {% endfor %}
            <button type="submit">Show the fancy map!</button>
        </form>

        {% if form.is_valid %}
           <p><img src="{{ map_url }}" alt="Google Maps Static Map"></p>
        {% else %}
           <p>Form is not valid</p>
        {% endif %}

    </body>
</html>

When I try to validate the form with example data in the Django console, it works fine:

>>> from frontend.forms import GoogleMapsStaticApiForm
>>> data = {'latitude':51.477222, 'longitude':0.0, 'zoom_level':12, 'map_width':400, 'map_height':400}
>>> f = GoogleMapsStaticApiForm(data)
>>> f.is_valid()
True

But when I enter the same data in the browser and press the submit button, the same template is reloaded but without the generated map. The form never seems to validate. Can anyone please tell me why this is the case? Thank you very much!

  • 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-05-30T16:57:52+00:00Added an answer on May 30, 2026 at 4:57 pm

    It looks like the form is empty because the input tag does not contain any name nor value attribute:

    <input type="text" class="input-small" placeholder="{{ field.html_name }}">
    

    For the browser to send any data, the input tag should have a name attribute:

    <input type="text" class="input-small" placeholder="{{ field.html_name }}" name="{{ field.html_name }}">
    

    For an input to show any value, the input should have a value attribute. To get the value of a field you’d do form.data['field_name'], but we can’t do that in the template. So we create a template filter. If you don’t know how to do that, refer to the documentation. Here’s a quick howto:

    1. Create a templatetags subdir in your app

    2. Create an empty __init__.py in that directory

    3. Create a file “yourapp_tags.py” in that directory

    Here’s an example of the code you could put in that script:

    from django import template
    
    register = template.Library()
    
    @register.filter
    def get_field_value(field):
        return field.form.data.get(field.name, '')
    

    Then you can use it in the template to set the initial field value:

    <input type="text" class="input-small" placeholder="{{ field.html_name }}" name="{{ field.html_name }}" value="{{ field|get_field_value }}">
    

    Don’t forget to {% load yourapp_tags %} in your template or get_field_value won’t be recognized !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why when I want to draw a polyline using Google maps V3.0 (JavaScript API)
I have a URL like: http://www.google.com/test.html?d=1232&u=32 and I want to add it as a
I'm using a Google Maps plugin, and I want it to show up on
I'm using google.maps javascript API v3. I need to translate a set of civic
I want to test the performance improvement that I could get by using Google's
$aa = Main:http://google-test.com:8080/service (or) $aa = http://google-test.com:8080/service2 I want to split this into two
I am developing web-application using Google Maps API and ASP.NET Ajax. Here is my
I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is
I created a google map and I want to add a list of markers
I want to know, is this legal? function test() { alert (hello) $(#loading).show(); }

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.