Page 1 of 1 (3 posts)

  • talks about »
  • django

Tags

Last update:
Wed Nov 26 17:55:07 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

Using TinyMCE rich text editor globally in django-admin

I spent quite a few frustrating hours trying to find a way to get TinyMCE to be used as the default control in textareas in my django admin interface. I know you can override individual admin forms to do this but there seems to be precious little written about how to do this globally for all admin forms.

I also (obviously) wanted to avoid any solution that forks django itself or satchmo (which I am using in this case too). Finally I found this nice way to do it by overloading the django admin template! Thanks Benshr!

  • Page 1 of 1 ( 3 posts )
  • django

Back to Top

Sponsors