django - Question mark in url pattern -


django 1.11.2

i need url pattern 2 cases:

  1. /blog/
  2. /blog/.json/

so, in case of json, i'll respond application/json content type.

this url pattern seems acceptable:

url(r'^blog/?(?p<json>\.json)?/$', blogfront.as_view()), 

at least, works. problem can't understand it.

the last ? match 0 or 1 repetitions of preceding re. it's ok. ? in middle capturing symbolic group.

what first question mark? mystery me. comment mean?

the first question mark makes preceeding / optional, making /blog.json/ valid. according question isn't want worth removing it


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -