Python webapp2 模块,uri_for() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用webapp2.uri_for()

项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def post(self):
        SubmitCrashHandler.common(self)
        if self.empty_query_string('crash', 'labels'):
            self.request_handler.redirect(uri_for('submit_crash'))
        else:
            crash = self.get_parameter('crash')
            argv = SubmitCrashHandler.csv_to_list(self.get_parameter('argv'))
            labels = SubmitCrashHandler.csv_to_list(self.get_parameter('labels'))
            # strip spaces around the crash report
            crash_report = CrashReports.add_crash_report(crash.strip(), argv=argv, labels=labels)
            message = 'Added Crash Report with fingerprint, count) => ({0}, {1})'.format(
                crash_report.fingerprint, CrashReport.get_count(crash_report.name))

            self.add_message(message)
            self.add_to_json('crash_report', CrashReport.to_json(crash_report))
            self.render('submit-crash.html')
项目:enkiWS    作者:juliettef    | 项目源码 | 文件源码
def make_local_url( locale, route_name, parameters ):
# example input: make_local_url( 'fr_FR' , 'login', { 'key1':'value1', 'key2':'value2', '_fragment':'top' })
# example output: http://www.mysite.com/login?locale=fr_FR&key1=value1&key2=value2#top
    temp_params = {} # modify a temporary dict so as not to modify parameters as this affects the jinja template
    url = ''
    for key, value in parameters.items():
        # parameters cleanup: remove parameters with blank values and UTF-8 encode the remaining values.
        if value:
            temp_params[ key ] = value.encode('utf-8')
    if locale:
        # add locale parameter to the parameters dictionnary
        # temp_params[ 'locale' ] = locale.encode('utf-8')
        url = webapp2.uri_for( 'locale-' + route_name, locale = locale.encode('utf-8'), _full = True, **temp_params )
    else:
        url = webapp2.uri_for( route_name, _full = True, **temp_params )
    return url
项目:webapp2    作者:GoogleCloudPlatform    | 项目源码 | 文件源码
def get_redirect_url(handler, **kwargs):
    return handler.uri_for('methods')
项目:webapp2    作者:GoogleCloudPlatform    | 项目源码 | 文件源码
def test_escaping(self):
        def get_req(uri):
            req = webapp2.Request.blank(uri)
            app.set_globals(app=app, request=req)
            handler = webapp2.RequestHandler(req, None)
            handler.app = req.app = app
            return req, handler

        req, handler = get_req('http://localhost:80/')
        uri = webapp2.uri_for('escape', name='with space')
        req, handler = get_req(uri)
        rsp = req.get_response(app)
        self.assertEqual(rsp.status_int, 200)
        self.assertEqual(rsp.body, b'with space')

        req, handler = get_req('http://localhost:80/')
        uri = webapp2.uri_for('escape', name='with+plus')
        req, handler = get_req(uri)
        rsp = req.get_response(app)
        self.assertEqual(rsp.status_int, 200)
        self.assertEqual(rsp.body, b'with plus')

        req, handler = get_req('http://localhost:80/')
        uri = webapp2.uri_for('escape', name='with/slash')
        req, handler = get_req(uri)
        rsp = req.get_response(app)
        self.assertEqual(rsp.status_int, 200)
        self.assertEqual(rsp.body, b'with/slash')
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def add_brand(cls, handler):
        brand = Link('Tessel Error Reporter', uri_for('home'))
        handler.add_parameter('brand', brand)
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def get(self):
        self.add_parameter('title', 'Tessel Error Reporter')
        self.add_breadcrumb('Tessel Error Reporter', uri_for('home'))
        RequestHandlerUtils.add_brand(self)
        RequestHandlerUtils.add_nav_links(self)
        directory_links = list()
        directory_links.append(Link('Trending Crashes', uri_for('trending_crashes')))
        directory_links.append(Link('Submit Crash', uri_for('submit_crash')))
        directory_links.append(Link('View Crash', uri_for('view_crash')))
        directory_links.append(Link('Update Crash Report', uri_for('update_crash_state')))
        directory_links.append(Link('Search', uri_for('search')))
        directory_links.append(Link('Update Global Preferences', uri_for('update_global_preferences')))
        self.add_parameter('directory_links', directory_links)
        self.render('index.html')
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def common(cls, handler):
        handler.add_parameter('title', 'Submit Crash Report')
        handler.add_breadcrumb('Home', uri_for('home'))
        handler.add_breadcrumb('Submit Crash', uri_for('submit_crash'))
        RequestHandlerUtils.add_brand(handler)
        RequestHandlerUtils.add_nav_links(handler)
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def common(cls, handler):
        handler.add_parameter('title', 'Show Crash')
        handler.add_breadcrumb('Home', uri_for('home'))
        handler.add_breadcrumb('View Crash', uri_for('view_crash'))
        RequestHandlerUtils.add_brand(handler)
        RequestHandlerUtils.add_nav_links(handler)
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def common(cls, handler):
        handler.add_parameter('title', 'Show Crash')
        handler.add_breadcrumb('Home', uri_for('home'))
        handler.add_breadcrumb('Trending Crashes', uri_for('trending_crashes'))
        RequestHandlerUtils.add_brand(handler)
        RequestHandlerUtils.add_nav_links(handler)
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def common(cls, handler):
        handler.add_parameter('title', 'Search crashes')
        handler.add_breadcrumb('Home', uri_for('home'))
        handler.add_breadcrumb('Search', uri_for('search'))
        RequestHandlerUtils.add_brand(handler)
        RequestHandlerUtils.add_nav_links(handler)
项目:t2-crash-reporter    作者:tessel    | 项目源码 | 文件源码
def common(cls, handler):
        handler.add_parameter('title', 'Update Global Preferences')
        handler.add_breadcrumb('Home', uri_for('home'))
        handler.add_breadcrumb('Update Global Preferences', uri_for('update_global_preferences'))
        RequestHandlerUtils.add_brand(handler)
        RequestHandlerUtils.add_nav_links(handler)
项目:cloud-memory    作者:onejgordon    | 项目源码 | 文件源码
def jinja2_factory(app):
    j = jinja2.Jinja2(app)
    j.environment.filters.update({
        'printjson': my_filters.printjson
    })
    j.environment.tests.update({
        })
    # j.package_path = 'views/templates'
    j.environment.globals.update({
        # Set global variables.
        'uri_for': webapp2.uri_for,
        # ...
    })
    return j
项目:flow-dashboard    作者:onejgordon    | 项目源码 | 文件源码
def jinja2_factory(app):
    j = jinja2.Jinja2(app)
    j.environment.filters.update({
        'printjson': my_filters.printjson
    })
    j.environment.tests.update({
        })
    j.environment.globals.update({
        # Set global variables.
        'uri_for': webapp2.uri_for,
    })
    return j