Page 1 of 1 (2 posts)

  • talks about »
  • image

Tags

Last update:
Wed Oct 1 00:55:10 2014

A Django site.

QGIS Planet

Django: serving an image from a remote server

For a current project (using django), I wanted to get a dynamically generated image from a remote map server and return the image to the django view as an object (as opposed to returning a URL as a string).

Here's how it's done (logic derived from this code snippet):

import urllib
import urllib2
import mimetypes

def serveMapImage( theArea ):
  # omitted: procedure to define the variable zoomExtents
  # from user-specified, database-derived variable theArea
  URI = "http://example.com/mapofsouthafrica-" + zoomExtents
  contents = urllib2.urlopen(URI).read()
  mimetype = mimetypes.guess_type(URI)
  response = HttpResponse(contents, mimetype=mimetype)

  return response
pixelstats trackingpixel

Django: serving an image from a remote server

For a current project (using django), I wanted to get a dynamically generated image from a remote map server and return the image to the django view as an object (as opposed to returning a URL as a string).

Here's how it's done (logic derived from this code snippet):

import urllib
import urllib2
import mimetypes

def serveMapImage( theArea ):
  # omitted: procedure to define the variable zoomExtents
  # from user-specified, database-derived variable theArea
  URI = "http://example.com/mapofsouthafrica-" + zoomExtents
  contents = urllib2.urlopen(URI).read()
  mimetype = mimetypes.guess_type(URI)
  response = HttpResponse(contents, mimetype=mimetype)

  return response

  • Page 1 of 1 ( 2 posts )
  • image

Back to Top

Sponsors