简体   繁体   中英

add/modify URL parameters

I have a page with several graphs, I would like to have a drop down menu next to each graph that allows me to filter by different parameter. The problem I find myself against is figuring out an easy way to

a) add a parameter to the current URL without deleting already existing parameters

b) checking if that parameter is already in the URL and modify it.

I might also have anchors on my URLs. Is there a simple way of achieving this without needing to parse the whole URL myself?

This would be the dropdown menu I use for the filter, and the idea is to use request in python to get the URL parameters.

<select name ="date range" onchange="this.form.submit()">
   <option value="today">Today</option>
   <option value="current week">Current week</option>
   <option value="last week">Last week</option>
   <option value="current month">Current month</option>
   <option value="last month">Last month</option>
</select>

Right now I've been using just URL parameters for this tasks but now I need to up my game a little bit and make it prettier

I found the solution. I created hidden values and used Jinja2 to access current url parameters and set default values in case they weren't set yet

<form method="GET">
            <select name ="date range" onchange="this.form.submit()" value="last week">
                <option value="today">Today</option>
                <option value="current week">Current week</option>
                <option value="last week">Last week</option>
                <option value="current month">Current month</option>
                <option value="last month">Last month</option>
            </select>
            <input type="hidden" name="days" value={{request.args.get('days', 30)}} />
            <input type="hidden" name="weeks" value={{request.args.get('weeks', 4)}} />
            <input type="hidden" name="months" value={{request.args.get('months', 4)}} />
            <input type="hidden" name="filter" value={{request.args.get('filter', 'version')}} />

        </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM