I'm building URLs that look like this, routing with Flask:
http://hostname/nris/resource/00001234 http://hostname/nris/resource/99000025
The last segment is an 8 digit integer that will match a string in my database. The leading zeros, if any, are significant.
I've implemented a custom regex converter, based on Does Flask support regular expressions in its URL routing?. That works fine as long as the numeric field starts with a non-zero. Here's my routing code (loaded within /nris/
):
@app.route('/numish/<regex("[0-9]{8}"):resourcenum>/')
def numish(resourcenum):
return "resourcenum: %s" % (resourcenum)
@app.route('/resource/<regex("[0-9]{8}"):resourcenum>/')
def resource_page(resourcenum):
return render_template('singlemap.html', propnris=resourcenum)
When I visit http://hostname/nris/numish/00000004, I see
resourcenum: 00000004
But when I display it in my template, all that's shown on the console is 4, and the database query performed in addSingleSiteLayer()
gets 4, not 00000004. Here's the Jinja code I'm using to generate JavaScript:
{% extends "maptemplate.html" %}
{% block mapcustom %}
console.log( "hello" );
console.log( {{propnris}} );
addSingleSiteLayer(map, {{propnris}} );
{% endblock %}
I could simply reformat the incoming value into an 8 character string with leading zeros. But I'd rather pass the parameter down so that it doesn't get truncated in the first place. Is there a clean way to do this?