Redirect not working

32 views
Skip to first unread message

jogaserbia

unread,
Dec 4, 2014, 12:58:55 PM12/4/14
to django...@googlegroups.com
Hi,  

I am trying to build a simple app.  On the index.html page an input box and button.  I put address in, click box to geocode and output some maps.  When I click on the button, the geocoding seems to work (see chrome output below), but it does not bring up the testing URL.   

This is what I get from chrome when I click on the button in the index.html, but nothing else happens. I bolded what I believe should redirect to the testing UR with the lng and lat data.   



Any ideas would be helpful. 

Ivan

index.html
...


     <script>


var geocoder

function searchAddress()

{
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
                 $.get("{% url 'testing' %}",
                 var position: results[0].geometry.location
                   {
                lat: position.lat(),
                lng: position.lng()
            }

        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }


     </script>

        <input id=address value='Toronto, ON'>
    <input id=searchAddress type=button value='Where are you'>




APP\urls.py 

urlpatterns = [
                       url(r'^$', views.index, name='index'),
                       url(r'^output/$', views.output, name='output'),
                       url(r'^testing/$', views.testing, name='testing'),
                       ]


views.py


def index(request):
    return render(request, 'locator/index.html')   



def testing(request):
    searchpoint = Point(float(request.GET.get('lon')), float(request.GET.get('lat')))
    atminfo = AtmInfo.objects.all()[:3]
    locations = AtmInfo.objects.distance(searchpoint).transform().order_by('distance')[:3]
    context = {'atminfo': atminfo, 'locations': locations, 'mainpnt': mainpoint}
    return render(request, 'locator/testing.html', context)



Florian Schweikert

unread,
Dec 4, 2014, 1:20:15 PM12/4/14
to django...@googlegroups.com
On 04/12/14 18:58, jogaserbia wrote:
> This is what I get from chrome when I click on the button in the
> index.html, but nothing else happens. I bolded what I believe should
> redirect to the testing UR with the lng and lat data.

does it work with hardcoded url?
is the testing url in the rendered index.html?
if the javascript doesn't try to load the testing url there is something
wrong with your js.
Maybe $.get is supposed to get a success function as parameter? (wild
guessing, I'm not a js guy)

and why "redirect not working"? Can't see any redirects in your code.

-- Florian

signature.asc

jogaserbia

unread,
Dec 4, 2014, 2:21:38 PM12/4/14
to django...@googlegroups.com, kel...@ist-total.org
Thanks for the reply Florian.

I am unclear on what exactly does the redirecting.  I think you are right about the .get. I stripped it out of the code, same issue.  You say there is no redirect, I am unclear on what exactly should be doing the redirecting.  

What has to be in the index.html to be able to call the testing view?  

Much appreciated.

Ivan

jogaserbia

unread,
Dec 4, 2014, 4:06:23 PM12/4/14
to django...@googlegroups.com, kel...@ist-total.org
I now realize that the button type input does not automatically submit a form in all browsers.  I changed the button type to submit, and it worked to call the testing view.

<form action= "{% url 'testing' %}" >                              
        <input id=address value='Toronto, ON'>                         
    <input id=searchAddress type=submit value='Where are you'>     
</form>                                                            


Thanks for pointing me in the right direction.   Now I am going to try to get the data from the function passed to the testing view.  
Reply all
Reply to author
Forward
0 new messages