No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

router.py 732B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. import re
  3. from .controllers import *
  4. from .urls import urls
  5. from ..main import root_url
  6. from lodel.settings import Settings
  7. def format_url_rule(url_rule):
  8. if url_rule.startswith('^'):
  9. res = url_rule.replace('^', '^'+root_url())
  10. else:
  11. res = root_url()+'.*'+url_rule
  12. return res
  13. def get_controller(request):
  14. url_rules = []
  15. for url in urls:
  16. url_rules.append((format_url_rule(url[0]), url[1]))
  17. # Returning the right controller to call
  18. for regex, callback in url_rules:
  19. p = re.compile(regex)
  20. m = p.search(request.PATH)
  21. if m is not None:
  22. request.url_args = m.groupdict()
  23. return callback
  24. return not_found