Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Create the "nearbyshops" View

Give Feedback

Nearly everything for the backend of our application is complete. In this video we’ll concentrate on the frontend in order to give our user a way to see the shops near their location.

What we’ll do in this video is create a Django view in our nearbyshops app and then route users to that view through the main

It might help to revisit what happens with an incoming request, which we covered in video #6.

Comments & Discussion

Abby Jones on Aug. 4, 2019

Hmmm, everything was going great when I left my code running last night. I logged in this morning and now I have a ton of errors in the libraries. It is also having trouble importing Distance from django.contrib.db.models.functions

Abby Jones on Aug. 4, 2019

Okay fixed that part (was missing .gis. in the Distance import. Now, it returns a blank html page. I think I can figure this one out lol.

Abby Jones on Aug. 4, 2019

Was missing a “


dthomas01 on March 18, 2020

Hi folks, Got a question about the RP tutorial for GeoDjango Nearby Shops. Wondered if anyone could point me in the right direction on switching units of measure. I’d be very grateful for any help.

Saw that nearest 6 shops displays as ‘meters’ with lots of decimal places. Tried converting output to be ‘miles’ instead…but not sure where in code or configuration to make that switch. (Agree that meter units are more precise than miles for the comparison to determine which shops indeed are nearest. Just wanted the output listing converted to miles, if possible. Not seeing how..because though value can be changed, the units still persist showing meters.)

Original code shows meters:

queryset = Shop.objects.annotate(distance=Distance("location", user_location)).order_by("distance")[0:6]

Webpage showed:

Cleaners Lobby Shop: 96.98014712 m 

Introduce division…but units were unchanged:

queryset = Shop.objects.annotate(distance=Distance("location", user_location)/1609.344).order_by("distance")[0:6]

Webpage still showed units symbol ‘m’:

Cleaners Lobby Shop: 0.060260669639306444 m

Maybe this is a GeoDjango config or such? Baffled....

Thanks, Dave

dthomas01 on March 19, 2020

Follow up to prior post… I solve the index.html shop.distance conversion from meters to miles myself…but not the rounding to limit how many decimal places. Passing this along for others.

Instead of using {{ }} : {{ shop.distance }} I switched to {{ }} : {{ shop.distance.mi }} mi

dthomas01 on March 19, 2020

Hello all, Okay I just now solved the decimal rounding issue too. Passing this along. So to get the distance both converted to miles and decimal rounding too, I’m using the following in the index.html file:

{{ }} ( {{ shop.distance.mi|floatformat:2 }} mi )


ankitzin on June 16, 2020

can we show these value in maps that would be great. Please give me so idea about that

Become a Member to join the conversation.