my url is http://example.com/en/cat/ap+da+w_pl
Now I have a-tag like this:
<a href="{{ url_for('category',
feature=request.path+"+"+att.get('u_sg'))}}">
{{ att.get('name') }}
</a>
request.path is giving me ' /en/cat/ap+da+wh_pl
' BUT, I need only /ap+da+w_pl
How to do it?
I need to pass only 'ap+da+w_pl' from out of request.path from HTML only, as I have to use it in pre-coded View of Flask and my view is like THIS:
@app.route('<lan_c>/cat/<string:feature>')
def category(feature, page):
You could split the result by /
and get the last key:
>>> r = 'http://example.com/en/cat/ap+da+w_pl'.split('/')
>>> r[-1]
'ap+da+w_pl'
This would work for /en/cat/ap+da+wh_pl
the same way:
>>> r = '/en/cat/ap+da+w_pl'.split('/')
>>> r[-1]
'ap+da+w_pl'
Prepend the /
if needed:
>>> '/'+(r[-1])
'/ap+da+w_pl'
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.