I am very new to Geodjango and have been running into some issues with a web mapping application. Currently, I am trying to make it so I can view all the schools on a map at once, as well as view individual schools on a map. I have been able to make it so I can view individual schools, but I am still unable to view all schools on a map at once.
This is how it looks when I am able to view a single school:
Here is what happens when I try to view all schools at once:
Am I going to the wrong url to do so or is there some other issue in the code that I am not seeing?
Here are my scripts:
schools_project/urls.py:
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import include, path
...
urlpatterns = [
url(r'^schools/', include('schools.urls')),
path('admin/', admin.site.urls),
]
schools/models.py:
from django.db import models
from django.contrib.gis.db import models as geomodels
...
class School(models.Model):
name = models.CharField(max_length=300, blank=False)
geometry = geomodels.PointField()
...
class Meta:
order = ('name',)
schools/apps.py:
from django.apps import AppConfig
...
class SchoolsConfig(AppConfig):
name = 'schools'
schools/admin.py:
from django.contrib import admin
from .models import School
from leaflet.admin import LeafletGeoAdmin
...
class SchoolAdmin(LeafletGeoAdmin):
list_display = ('name', 'geometry')
...
admin.site.register(School, SchoolAdmin)
schools/urls.py:
from django.conf.urls import url
from . import views
...
app_name = 'schools'
...
urlpatterns = [
url(r^school/(?P<pk>[0-9]+)$',
views.SchoolsDetailView.as_view(), name='school-detail'),
]
schools/views.py:
from django.views.generic import DetailView
from .models import School
...
class SchoolsDetailView(DetailView):
"""
School detail view.
"""
template_name = r"C:\Users\Drew\Desktop\djangoproject\schools_project\templates\school-detail"
model = School
school-detail.html (template):
<!DOCTYPE html>
<html>
<Title>Public Schools in Aurora, Colorado</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
{% load leaflet_tags %}
{% leaflet_css %}
{% leaflet_js %}
<div class="w3-container">
<h1 style="text-align: center; color: #ffffff;"><b><font size="+3">Public Schools in Denver and Aurora, Colorado</font></b></h1>
<h2 style= "color: #ffffff;"><b><i>{{ school.name }}</i></b></h2>
{% leaflet_map "main" callback="map_init" %}
</div>
<style>
.leaflet-container { /* all maps */
width: 1450px;
height: 700px;
}
#specialbigmap {
height: 800px;
}
/* Resize the "display_raw" textbox */
.django-leaflet-raw-textarea {
width: 100%;
}
body {
background-color: #000000;
}
h1 {
border-style: solid;
}
h2 {
text-align: center;
}
</style>
<script type="text/javascript">
function map_init(map, options) {
// get point lat and lon
var lon = "{{ school.geometry.x }}";
var lat = "{{ school.geometry.y }}";
// zoom to point & add it to map
map.setView([lat, lon], 17);
L.marker([lat, lon]).addTo(map);
}
</script>
</html>
Does anybody have any ideas or tips on how I can view all points on a map at the same time?