Skip to main content

Use Leaflet in your django projects

Project description

*django-leaflet* allows you to use `Leaflet <>`_
in your `Django <>`_ projects.



pip install django-leaflet


* Add ``leaflet`` to your ``INSTALLED_APPS``

* Add the HTML header::

{% load leaflet_tags %}

{% leaflet_js %}
{% leaflet_css %}

* Add the map in your page, providing a name::

{% leaflet_map "yourmap" %}

* Your maps shows up!

Use Leaflet API

You can use the *Leaflet* API as usual in the map initialization callback::

<script type="text/javascript">
function yourmapInit(map, bounds) {
L.marker([50.5, 30.5]).addTo(map);

Customize map size



.leaflet-container { /* all maps */
width: 600px;
height: 400px;

#specialbigmap {
height: 800px;



In order to configure *django-leaflet*, just add a new section in your

# conf here

Spatial extent

You can configure a global spatial extent for your maps, that will
automatically center your maps, restrict panning and add reset view and scale
controls. (*See advanced usage to tweak that.*)::

'SPATIAL_EXTENT': (5.0, 44.0, 7.5, 46)

Default tiles layer

To globally add a tiles layer to your maps::

'TILES_URL': 'http://{s}{z}/{x}/{y}.png'

This setting can also be a list of tuples (name, url) ! A layer switcher
will then be added automatically.

Leaflet version

By default, it runs the last stable version (*0.4.5*) of Leaflet. But it is
possible to run the ``legacy`` version (*0.3.1*) or the ``unstable`` under
development (*master*)::


Scale control

Disable scale control with km and miles::

'SCALE': False

Advanced usage

``{% leaflet_map %}`` tag parameters

* ``callback``: javascript function name for initialization callback.
(Default: ``name + Init``). Example::

{% leaflet_map "yourmap" callback="window.customMap" %}

* ``fixextent``: control if map initial view shoud be set to extent setting.
(Default: ``True``). Setting fixextent to ``False`` will prevent view reset
and scale controls to be added.


It is possible to setup the map spatial reference in ``LEAFLET_CONFIG``::

'SRID': 2154 # See

Additional parameter is required to compute scale levels : the tiles extent in
local projection::

'TILES_EXTENT': [700000, 6325197, 1060000, 6617738],

For more information, `have a look at this example <>`_.

By default, Django will try to load the spatial reference from your static
files at "proj4js/{{ srid }}.js". If it fails, it will eventually rely on


* Mathieu Leplatre <>


.. |makinacom| image::
.. _makinacom:


* Lesser GNU Public License
* Leaflet Copyright - 2010-2011 CloudMade, Vladimir Agafonkin


0.3.0 (2012-10-26)

* Remove max resolution setting since it can be computed
* Allow scale control even if view is not set
* Upgrade Leaflet to 0.4.5

0.2.0 (2012-09-22)

* Fix packaging of templates
* Use template for <head> fragment
* Do not rely on by default
* Default settings for SRID
* Default settings for map extent
* Default map height
* Default tiles base layer
* map variable is not global anymore

0.1.0 (2012-08-13)

* Initial support for map projection
* Show zoom scale by default
* Spatial extent configuration
* Initialization callback instead of global JS variable
* Leaflet version switching
* Global layers configuration

0.0.2 (2012-03-22)

* Add IE conditional CSS

0.0.1 (2012-03-16)

* Initial working version

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-leaflet, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size (276.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page