print full_url = request.get_host()+request.get_full_path()
结果:
127.0.0.1:8000/test/en/
或
127.0.0.1:8000/test/ru/
如何判断字符串结尾是/en/
还是/ru/
最佳答案
使用endswith
:
full_url.endswith('/en/') or full_url.endswith('/ru/')
如果你发现有更多的扩展需要覆盖,你可以考虑使用any
:
any(s.endswith(ext) for ext in ['/ru/', '/en/'])
关于python - Python 中的字符串操作。解析网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17744181/