def render_url(cfg, pathinfo, querystring=""): """ Takes a url and a querystring and renders the page that corresponds with that by creating a Request and a Douglas object and passing it through. It then returns the resulting Response. :param cfg: the config.py dict :param pathinfo: the ``PATH_INFO`` string; example: ``/dev/douglas/firstpost.html`` :param querystring: the querystring (if any); example: debug=yes :returns: a douglas ``Response`` object. """ from douglas.app import Douglas if querystring: request_uri = pathinfo + '?' + querystring else: request_uri = pathinfo parts = urlparse(cfg['base_url']) env = { 'HTTP_HOST': parts.netloc, 'HTTP_PORT': parts.port, 'HTTP_USER_AGENT': 'static renderer', 'PATH_INFO': pathinfo, 'QUERY_STRING': querystring, 'REMOTE_ADDR': '', 'REQUEST_METHOD': 'GET', 'REQUEST_URI': request_uri, 'SCRIPT_NAME': '', 'wsgi.url_scheme': 'http', 'wsgi.errors': sys.stderr, 'wsgi.input': None } p = Douglas(cfg, env, {'COMPILING': 1}) p.run(compiling=True) return p.get_response()
def render_url(cdict, pathinfo, querystring=""): """ Takes a url and a querystring and renders the page that corresponds with that by creating a Request and a douglas object and passing it through. It then returns the resulting Response. :param cdict: the config.py dict :param pathinfo: the ``PATH_INFO`` string; example: ``/dev/douglas/firstpost.html`` :param querystring: the querystring (if any); example: debug=yes :returns: a douglas ``Response`` object. """ from douglas.app import Douglas if querystring: request_uri = pathinfo + "?" + querystring else: request_uri = pathinfo env = { "HTTP_HOST": "localhost", "HTTP_REFERER": "", "HTTP_USER_AGENT": "static renderer", "PATH_INFO": pathinfo, "QUERY_STRING": querystring, "REMOTE_ADDR": "", "REQUEST_METHOD": "GET", "REQUEST_URI": request_uri, "SCRIPT_NAME": "", "wsgi.errors": sys.stderr, "wsgi.input": None } data = {"STATIC": 1} p = Douglas(cdict, env, data) p.run(static=True) return p.get_response()