Django view to display weather measurements for selected location and dates
Not sure this will solve all your problems, but you can give those GET parameters default values in case they don't exist. In my example below, they are given the default value of None. This should simplify things a bit.

def index(request):

    print('hello')


    location = request.GET.get('location', None)
    selectstartdate = request.GET.get('selectstartdate', None)
    selectenddate = request.GET.get('selectenddate', None)

    if location is not None or selectstartdate is not None and selectenddate is not None:

        # Get locations from db.
        locations = Location.objects.all()

        # Prepare locations dictionary for google map layer js.
        locs_ls = []
        for loc in locations:
            lat = loc.latitude
            lon = loc.longitude
            name = loc.name
            site_id = loc.site_id

            locs_ls.append({'site_id': site_id, 'name': name, 'lat': lat, 'lon': lon})

        context = {
            'locs_ls': locs_ls,
        }

        return render(request, 'locations/index.html', context)

    else:

        params = {
            'location': location,
            'selectstartdate': selectstartdate,
            'selectenddate': selectenddate,
        }

        context = single_location(**params)

        return render(request, 'locations/location.html', context)