Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25

Daniel Flick daniel.p.flick at gmail.com
Thu Oct 19 12:46:48 EDT 2017


The problem was with the validation code.  Within the python section of the template, the class IPv4Interface will throw an exception due to the invalid value during the validation process. Therefore, the server rejects the form data and the template is not created.

Solution: It would work if you add an error handling to the python section of the template.

    <%!
        ## python module-level code
        import ipaddress
    %>
    <%def name="get_address(ip_string)">
        <%
        try:
            return ipaddress.IPv4Interface(ip_string).ip
        except Exception:
            return "FAIL_OR_EMPTY"
        %>
    </%def>
    ! Variable Input: ${LAN_IP}
    ${get_address(LAN_IP)}
Explanation: During the server-side validation of the HTML form, the configuration template is rendered with a dummy parameter set to verify the syntax (see file app/forms.py, class ConfigTemplateForm). Your config template is validated with the following parameter set during the form validation:

    {
        "hostname": "test",
        "LAN_IP": "test"
    }




More information about the Python-list mailing list