render_part()
method in recognizers.py
module is not doing just plain template rendering.
It does, in order:
- Automatic Regex Conversion
- Template Rendering (with
regEx
is the only available/injected method in the context) - Variable Detection
{{varname}}
variable detection cannot be handled by template rendering since varname
is not known
before hand and it cannot be added to the context. Therefore it should be extracted with a regex
{{(.*?)}}
after the template rendering happens, or vice versa.
Here are some examples that categorizes the rendering types:
/{{var1longname}}/prefix-{{var2}}-middle-{{var3}}/{{regEx('(.*)_(.*)', 'var4', 'var5')}}
^ ^ ^
┆Variable Det. ┆Automatic Regex Conversion ┆Template Rendering
?param1={{var1longname}}¶m2=prefix-{{var2}}-middle-{{var3}}¶m3={{regEx('(.*)_(.*)', 'var4', 'var5')}}
^ ^ ^
┆Variable Det. ┆Automatic Regex Conversion ┆Template Rendering
In conclusion, as it can be understand from the examples above; applying template rendering to HTTP components as
a whole is not possible because it's just not plain template rendering. There are additional logic. So it needs to be
parsed into key-value pairs first then the value needs to be passed into render_part()
method.