String operation in Python. Parse URL -


print full_url = request.get_host()+request.get_full_path() 

result:

127.0.0.1:8000/test/en/

or

127.0.0.1:8000/test/ru/

how check if end of string /en/ or /ru/

use endswith:

full_url.endswith('/en/') or full_url.endswith('/ru/') 

if find there more extensions have cover, may consider using any:

any(s.endswith(ext) ext in ['/ru/', '/en/']) 

Comments