0

I'm building a GIS-related web application, and the way it displays the contents of the database on a map is pretty straightforward: the view collects several (currently 122) GeoJSON files and passes them to the template. The template iterates all of them and displays them (using Leaflet). However, I cannot manage to make it work, as every attempt results in a Memory Error.

The database I'm using is a PostgreSQL one, in case it helps. I'm also using a TextField in the model, is it possible that to be source of the issue?

Any advice will be much appreciated :)

The view:

geodata = GeojsonData.objects.filter(connection = my_con).iterator()
view = "map"
return render(request, "map.html", {'geojsonData': geodata})

The template:

{% for dat in geojsonData %}
{% with dat.name as name %}
{% with dat.geodata as gj %}

{{gj}}

L.geoJSON(name).addTo(map);


{% endwith %}
{% endwith %}
{% endfor %}

The model:

class GeojsonData(models.Model):
    name = models.CharField(max_length=2000, unique=True)
    connection= models.ForeignKey(Connection, related_name='Connection', default=1)
    geodata = models.TextField()

The traceback:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/map/1/

Django Version: 1.11.4
Python Version: 3.6.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'myapp.apps.myappConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner
  41.             response = get_response(request)

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "C:\Users\Xabi\Desktop\...\views.py" in mapa
  92.       return render(request, "map.html", {'geojsonData': geodata})

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\shortcuts.py" in render
  31.     return HttpResponse(content, content_type, status)

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\http\response.py" in __init__
  303.         self.content = content

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\http\response.py" in content
  336.             content = self.make_bytes(value)

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\http\response.py" in make_bytes
  247.             return bytes(value.encode(self.charset))

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py" in _curried
  15.         return _curried_func(*(args + moreargs), **dict(kwargs, **morekwargs))

File "C:\Users\Xabi\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\safestring.py" in _proxy_method
  107.             return SafeBytes(data)

Exception Type: MemoryError at /map/1/
Exception Value: 

1 Answer 1

1

Not sure if you've already solved your problem. But maybe instead of doing the loop in your template, you can do the loop in python and pass the end result to your template?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.