Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango urlpatterns frustrating problem with trailing slashes
    primarykey
    data
    text
    <p>All of the examples I can find of urlpatterns for django sites have a separate entry for incoming urls that have no leading slash, or the root folder. Then they handle subfolders on each individual line. I don't understand why a simple</p> <pre><code>/? </code></pre> <p>regular expression doesn't permit these to be on one simple line. </p> <p>Consider the following, let's call the Django project Baloney and the App name is Cheese. So in the project urls.py we have something like this to allow the apps urls.py to handle it's requests...</p> <pre><code>urlpatterns = patterns('', (r'^cheese/', include('Baloney.Cheese.urls')), ) </code></pre> <p>then inside of the Cheese apps urls.py, I don't understand why this one simple line would not trigger as true for all incoming url subpaths, including a blank value...</p> <pre><code>urlpatterns = patterns('', (r'^(?P&lt;reqPath&gt;.*)/?$', views.cheeseapp_views), ) </code></pre> <p>Instead, it matches the blank case, but not the case of a value present. So...</p> <pre><code>http://baloneysite.com/cheese/ --&gt; MATCHES THE PATTERN http://baloneysite.com/cheese/swiss --&gt; DOES NOT MATCH </code></pre> <p>Basically I want to capture the reqPath variable to include whatever is there (even blank or '') but not including any trailing slash if there is one.</p> <p>The urls are dynamic slugs pulled from the DB so I do all the matching up to content in my views and just need the url patterns to forward the values along. I know that the following works, but don't understand why this can't all be placed on one line with the /? regular expression before the ending $ sign.</p> <pre><code>(r'^$', views.cheeseapp_views, {'reqPath':''}), (r'^(?P&lt;reqPath&gt;.*)/$', views.cheeseapp_views), </code></pre> <p>Appreciate any insights.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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