Рубрики
Без рубрики

📦 Создать строку из шаблона URL -адреса

от FunctorFlow Import ff # Сгенерировать строку из шаблона и значений URL: Pattern = … Tagged with Repit, Python, Functorflow.

from functorflow import ff

# Generate string from URL pattern and values:


pattern = ff("make-url-pattern", pattern="/api/products(/:id)")
res = pattern.stringify( vals={ "id": 43 } ) 

print(res) # '/api/products/43'



# Match pattern against string and extract values:

pattern = ff("make-url-pattern", pattern="/api/products(/:id)")
res = pattern.match( url="/api/products/5" ) 

print(res) # {'id': '5'}

Перестаньте тратить время на установку и настройку библиотек Python. Используйте их сразу. 📦functorflow Мгновенно автоматически установить и автоконфигруйте их для вас.

Оригинал: “https://dev.to/samandar/generate-string-from-url-pattern-ec2”