I am trying to get GeoJSON response using django rest framework but facing issue
argument of type 'NoneType' is not iterable
This is my code
class NewPark(models.Model):
name = models.CharField(max_length=256)
geometry = models.GeometryField(srid=3857, null=True, blank=True)
objects = models.GeoManager()
class Meta:
db_table = u'new_park'
def __unicode__(self):
return '%s' % self.name
class NewParkSerializer(GeoFeatureModelSerializer):
class Meta:
model = NewPark
geo_field = "geometry"
fields = ('id', 'name', 'geometry')
class NewParkViewSet(viewsets.ModelViewSet):
def get_queryset(self):
queryset = NewPark.objects.all()
return queryset
When i change serialize type to 'erializers.GeoModelSerializer' then it is working, but i want GEOJSON response
I have searched about GeoFeatureModelSerializer but cannot find any example geo_field = "geometry". All example are about geo_field = "point"
Please help me to figure out this issue?
You might only have the above error in the browsable API, because the default djanog-rest-framework html template renderer does not work with the GeoJson format.
To test if that is the case, try to call your api endpoint requesting it in json format, i.e. /api/newpark.json
or equivalently /api/newpark?format=json
. This should show you geojson data, if it does your backend API is fine, and the problem is the browsable html form.
If you want a browsable API for your GeoJson endpoint, then you might need to change the html template used to render your API end point.