What do Dollar and Caret ( $ and ^) sign in Django urls mean?

$ and ^ are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,” and the dollar sign means “require that the pattern matches the end of the string.”

For example consider the  following url pattern

urlpatterns = patterns('',
    url(r'^hello/$', hello),
)

Without the dollar sign at the end it will match any url starting with hello like

  • hello/satish
  • hello/gandham/
  • hello/satish/123/pqr

Note: use url(r'^$', my_homepage_view), to match root.

One Reply to “What do Dollar and Caret ( $ and ^) sign in Django urls mean?”

Leave a Reply

Your email address will not be published. Required fields are marked *