설명 없음
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 897B

1234567891011121314151617181920212223242526272829303132333435
  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. '''match = re.search(regex, request.PATH)
  25. if match is not None:
  26. request.url_args = match.groups()
  27. return callback
  28. '''
  29. return not_found