Resolving absolute URLs
An absolute URL includes the scheme, host, and port of a URL, as in the following format, scheme://host:port/path?query
. This is an example of an absolute URL: https://www.example.com:8000/my_path?query=my_query_value.
Next, we will resolve an absolute URL while introducing the practice of using custom context processors.
Creating a context processor
Context processors are useful in many ways: they provide context that is shared globally among all templates and views within a project. Alternatively, the context being created in a view can only be used by the template that the view is using and no other templates. In the next example, we will create and then activate a custom global context processor where we will add the base URL of the site. We will call the context variable base_url
, referring to scheme://host:port
of the URL found throughout this project's site.
Follow these steps to create your context processor:
- In the same folder...