Storing the start/end dates into python with daterangepicker

Viewed 14

For my flask web app, I would like to store the start and end dates from daterangepicker into python when the apply button is pressed. I have this code from the source website :

<input type="text" name="daterange" value="01/01/2018 - 01/15/2018" />
<script>
$(function() {
  $('input[name="daterange"]').daterangepicker({
    opens: 'left'
  }, function(start, end, label) {
    console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
  });
});
</script>

And the backend code something like this:

app = Flask(__name__)
@app.route('/', methods = ['POST','GET'])
def main():
    if request.method == "POST"
    #save start date and end dates into python here 
    else:
        return render_template('main.html')

start.format('YYYY-MM-DD') and end.format('YYYY-MM-DD') are exactly what I need to be used in python. It would also be great if the page would refresh upon hitting 'apply'.

0 Answers
Related