We use regular expressions to match these url paths to their corresponding request handler (aka View). If a path, either dynamic or static, is matched the View will then handle the request and return a response to the User. If a path is not matched, Django will automatically send a 404 Page Not Found response.
If you're creting a RESTful API using Django, this can be a good solution when developers POST data directly to endpoint URL. When using APPEND_SLASH , if they accidently sent it without trailing slash, and your urlconf is WITH a trailing slash they would get an exception about data lose when redirecting POST requests.
Yes, if they upgrade to django-4.0, url will no longer be available.
Django offers a way to name urls so it's easy to reference them in view methods and templates. The most basic technique to name Django urls is to add the name attribute to url definitions in urls.py .
Try:
^(?P<page>[-\w]+)/$
[-\w] will accept a-z 1-9 and dash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With