Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple URL segment in Flask and other Python frameowrks
    text
    copied!<p>I'm building an application in both Bottle and Flask to see which I am more comfortable with as Django is too much 'batteries included'.</p> <p>I have read through the routing documentation of both, which is very clear and understandable but I am struggling to find a way of dealing with an unknown, possibly unlimited number of URL segments. ie:</p> <pre>http://www.example.com/seg1/seg2/seg3/seg4/seg5.....</pre> <p>I was looking at using something like <pre><code>@app.route(/&lt; path:fullurl >)</code></pre> using regex to remove unwanted characters and splitting the fullurl string into a list the same length as the number of segments, but this seems incredibly inefficient.</p> <p>Most PHP frameworks seem to have a method of building an array of the segment variable names regardless of the number but neither Flask, Bottle or Django seem to have a similar option, I seem to need to specify an exact number of segments to capture variables. A couple of PHP cms's seem to collect the first 9 segments immediately as variables and anything any longer gets passed as a full path which is then broken down in the way I mentioned above.</p> <p>Am I not understanding the way things work in URL routing? Is the string splitting method really inefficient or the best way to do it? Or, is there a way of collecting an unknown number of segments straight into variables in Flask?</p> <p>I'm pretty new on Python frameworks so a five year olds explanation would help,</p> <p>many thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload