What is the difference between:
path('index/', views...
And
path(r'^index/$', views...
I use the first example but I see everyone using the raw string syntax in examples I look up. Are there any differences between the way Django handles the two examples?
The
pathmethod is the full match method, so when your path will be exactly as described, you will have the possibility to handle the request with the view that you've described.The
re_pathallows you more control with regular expressions. Let's extend your exampler"^index/?$", here "?" sign allows the user to use the trailing slash "/" at the end of the URL or not use.You can play with regexp here: https://regex101.com
The Django documentation about re_path is here: https://docs.djangoproject.com/en/dev/topics/http/urls/#using-regular-expressions
The business needs could be very complex and maybe you won't be able to make a match for a needed URL format with just the
pathfeatures, but in 99% this option will be enough.