Python bottle.template() Examples
The following are 30
code examples of bottle.template().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bottle
, or try the search function
.
Example #1
Source File: cli.py From mailur with GNU General Public License v3.0 | 6 votes |
def icons(): import json import bottle font = root / 'assets/font' sel = (font / 'selection.json').read_text() sel = json.loads(sel) sel_pretty = json.dumps(sel, indent=2, ensure_ascii=False, sort_keys=True) (font / 'selection.json').write_text(sel_pretty) icons = [ (i['properties']['name'], '\\%s' % hex(i['properties']['code'])[2:]) for i in sel['icons'] ] tpl = str((font / 'icons.less.tpl').resolve()) txt = bottle.template( tpl, icons=icons, template_settings={'syntax': '{% %} % {{ }}'} ) f = font / 'icons.less' f.write_text(txt) print('%s updated' % f)
Example #2
Source File: web.py From TedEval with MIT License | 6 votes |
def index(): _,images_list = get_samples() page = 1 if 'p' in request.query: page = int(request.query['p']) subm_data = get_all_submissions() vars = { 'url':url, 'acronym':acronym, 'title':title, 'images':images_list, 'method_params':method_params, 'page':page, 'subm_data':subm_data, 'submit_params':submit_params, 'instructions':instructions, 'extension':gt_ext } return template('index',vars)
Example #3
Source File: server.py From steam-buddy with MIT License | 6 votes |
def platform(platform): if platform == "flathub": return template('flathub', app_list=FLATHUB_HANDLER.get_installed_applications(), isInstalledOverview=True, platform=platform, platformName=PLATFORMS[platform]) shortcuts = sorted(load_shortcuts(platform), key=lambda s: s['name']) data = [] for shortcut in shortcuts: filename = None banner = None hidden = 'hidden' if 'hidden' in shortcut and shortcut['hidden'] else '' if 'banner' in shortcut: filename = os.path.basename(shortcut['banner']) banner = '/banners/{platform}/{filename}'.format(platform=platform, name=shortcut['name'], filename=filename) data.append({'hidden': hidden, 'filename': filename, 'banner': banner, 'name': shortcut['name']}) return template('platform.tpl', shortcuts=data, platform=platform, platformName=PLATFORMS[platform])
Example #4
Source File: phillip.py From phillip with GNU General Public License v3.0 | 6 votes |
def play(code, delay=6, real_delay=0): if not validate(code): return request_match_page() + template('Invalid code <b>{{code}}</b>', code=code) if cull_times() >= MAX_GAMES: return request_match_page() + template('Sorry, too many games running') command = 'sbatch -t 20:00 -c 2 --mem 1G -x node[001-030]' # --qos tenenbaum' command += ' --output slurm_logs/server/%s.out' % code command += ' --error slurm_logs/server/%s.err' % code command += ' netplay.sh %s %s %s' % (code, delay, real_delay) print(command) try: subprocess.run(command.split()) except: return request_match_page() + template('Unknown error occurred. Make sure your netplay code <b>{{code}}</b> is valid.', code=code) start_times.append(time.time()) return request_match_page() + template('Phillip netplay started with code <b>{{code}}</b>!', code=code)
Example #5
Source File: server.py From sysdweb with GNU General Public License v3.0 | 6 votes |
def get_main(): services = [] for service in config.sections(): service_status = get_service_action(service, 'status') if service_status['status'] == 'not-found': cls = 'active' elif service_status['status'] == 'inactive' or service_status['status'] == 'failed': cls = 'danger' elif service_status['status'] == 'active': cls = 'success' else: cls = 'warning' disabled_start = True if cls == 'active' or cls == 'success' else False disabled_stop = True if cls == 'active' or cls == 'danger' else False disabled_restart = True if cls == 'active' or cls == 'danger' else False services.append({'class': cls, 'disabled_start': disabled_start, 'disabled_stop': disabled_stop, 'disabled_restart': disabled_restart, 'title': config.get(service, 'title'), 'service': service}) return template('index', hostname=gethostname(), services=services)
Example #6
Source File: webinterface.py From RPi-InfoScreen-Kivy with GNU General Public License v3.0 | 6 votes |
def update_config(self, screen=None): if screen in self.screens: # Build the path to our config file conffile = os.path.join(self.folder, "screens", screen, "conf.json") # Open the file and load the config with open(conffile, "r") as cfg_file: params = json.load(cfg_file) # We only want the user to edit the "params" section so just # retrieve that part conf = json.dumps(params.get("params", dict()), indent=4) # Build the web page return template(SCREEN_CONFIG, screen=screen, conf=conf)
Example #7
Source File: main.py From indiwebmanager with GNU Lesser General Public License v2.1 | 6 votes |
def main_form(): """Main page""" global saved_profile drivers = collection.get_families() if not saved_profile: saved_profile = request.get_cookie('indiserver_profile') or 'Simulators' profiles = db.get_profiles() return template(os.path.join(views_path, 'form.tpl'), profiles=profiles, drivers=drivers, saved_profile=saved_profile, hostname=hostname) ############################################################################### # Profile endpoints ###############################################################################
Example #8
Source File: sample.py From python-for-IBM-i-examples with MIT License | 6 votes |
def cmd_toolkit(): cl_statement = request.forms.get('cl') # xmlservice itool = iToolKit() itransport = iDB2Call() itool.add(iCmd5250(cl_statement, cl_statement)) itool.call(itransport) # results from list data = '' for output_outer in itool.list_out(): for output_inner in output_outer: data += output_inner return template('cmd', data=data)
Example #9
Source File: app.py From blog-code-examples with MIT License | 6 votes |
def chart(num_bars): """Creates a bar chart with the desired number of bars in a chart.""" if num_bars <= 0: num_bars = 1 data = {"days": [], "bugs": [], "costs": []} for i in range(1, num_bars + 1): data['days'].append(i) data['bugs'].append(random.randint(1,100)) data['costs'].append(random.uniform(1.00, 1000.00)) hover = create_hover_tool() plot = create_bar_chart(data, "Bugs found per day", "days", "bugs", hover) script, div = components(plot) return template(TEMPLATE_STRING, bars_count=num_bars, the_div=div, the_script=script)
Example #10
Source File: cprofilev.py From cprofilev with MIT License | 6 votes |
def process_line(cls, line): # Format header lines (such that clicking on a column header sorts by # that column). if re.search(cls.HEADER_LINE_REGEX, line): for key, val in cls.SORT_ARGS.items(): url_link = bottle.template( "<a href='{{ url }}'>{{ key }}</a>", url=cls.get_updated_href(SORT_KEY, val), key=key) line = line.replace(key, url_link) # Format stat lines (such that clicking on the function name drills into # the function call). match = re.search(cls.STATS_LINE_REGEX, line) if match: prefix = match.group(1) func_name = match.group(2) if func_name not in cls.IGNORE_FUNC_NAMES: url_link = bottle.template( "<a href='{{ url }}'>{{ func_name }}</a>", url=cls.get_updated_href(FUNC_NAME_KEY, func_name), func_name=func_name) line = bottle.template( "{{ prefix }}({{ !url_link }})\n", prefix=prefix, url_link=url_link) return line
Example #11
Source File: proxy.py From github-pages-basic-auth-proxy with MIT License | 6 votes |
def proxy_trough_helper(url): print ('PROXY-GET: {0}'.format(url)) proxy_response = requests.get(url) if proxy_response.status_code == 200: if proxy_response.headers['Last-Modified']: response.set_header('Last-Modified', proxy_response.headers['Last-Modified']) if proxy_response.headers['Content-Type']: response.set_header('Content-Type', proxy_response.headers['Content-Type']) if proxy_response.headers['Expires']: response.set_header('Expires', proxy_response.headers['Expires']) return proxy_response else: return HTTPResponse(status=proxy_response.status_code, body=template(error_tpl, headline='Error {0}'.format(proxy_response.status_code), error='error during proxy call')) # # BOTTLE APP #
Example #12
Source File: usermanager.py From conifer with Apache License 2.0 | 6 votes |
def send_invite(self, email, email_template, host): entry = self.invites[email] if not entry: print('No Such Email In Invite List') return False hash_ = base64.b64encode(os.urandom(21)).decode('utf-8') entry['hash_'] = hash_ full_hash = email + ':' + hash_ invitekey = base64.b64encode(full_hash.encode('utf-8')).decode('utf-8') email_text = template( email_template, host=host, email_addr=email, name=entry.get('name', email), invite=invitekey, ) self.cork.mailer.send_email(email, 'You are invited to join webrecorder.io beta!', email_text) entry['sent'] = str(datetime.utcnow()) return True
Example #13
Source File: door_lock_server.py From pi_magazine with MIT License | 6 votes |
def new_item(): global attempts # Get the password entered in the password field of the form pwd = request.POST.get('password', '').strip() # check to see if tehre have been too many failed attemts if attempts >= MAX_ATTEMPTS: return template('lockout.tpl') # unlock the door if the password is correct if pwd == PASSWORD: attempts = 0 unlock_door() return template('opened.tpl') else: attempts += 1 return template('failed.tpl') # Start teh webserver running on port 80
Example #14
Source File: cprofilev.py From cprofilev with MIT License | 6 votes |
def route_handler(self): self.stats = Stats(self.profile) func_name = bottle.request.query.get(FUNC_NAME_KEY) or '' sort = bottle.request.query.get(SORT_KEY) or '' self.stats.sort(sort) callers = self.stats.show_callers(func_name).read() if func_name else '' callees = self.stats.show_callees(func_name).read() if func_name else '' data = { 'title': self.title, 'stats': self.stats.sort(sort).show(func_name).read(), 'callers': callers, 'callees': callees, } return bottle.template(STATS_TEMPLATE, **data)
Example #15
Source File: chat.py From youtube-dl-nas with MIT License | 5 votes |
def index(): return template('index')
Example #16
Source File: echo.py From youtube-dl-nas with MIT License | 5 votes |
def index(): return template('index')
Example #17
Source File: weblcds.py From artisan with GNU General Public License v3.0 | 5 votes |
def index(): if not (showbt and showet): showspace_str = "inline" else: showspace_str = "none" if showbt: showbt_str = "inline" else: showbt_str = "none" if showet: showet_str = "inline" else: showet_str = "none" return template('artisan.tpl', port=str(port), nonesymbol=nonesymbol, timecolor=timecolor, timebackground=timebackground, btcolor=btcolor, btbackground=btbackground, etcolor=etcolor, etbackground=etbackground, showbt=showbt_str, showet=showet_str, showspace=showspace_str) # Static Routes
Example #18
Source File: bottle_example.py From trace-examples with BSD 3-Clause "New" or "Revised" License | 5 votes |
def index(name): return template('<b>Hello {{name}}</b>!', name=name)
Example #19
Source File: web_sensor.py From raspberrypi_cookbook_ed3 with MIT License | 5 votes |
def index(): return template('justgage.1.0.1.min.js')
Example #20
Source File: webapp.py From modernpython with MIT License | 5 votes |
def show_main_page(user=None) -> dict: user = user or get_logged_in_user() if user is None: return template('login', null=None) heading = 'Posts from people you follow' posts = pubsub.posts_for_user(user) return dict(user=user, posts=posts, heading=heading, comb=comb)
Example #21
Source File: test_bottle.py From aws-xray-sdk-python with Apache License 2.0 | 5 votes |
def test_render_view(): path = '/view' response = app.get(path) assert response.text == "<h1>Hello Bottle!</h1>\n<p>How are you?</p>\n" segment = recorder.emitter.pop() assert not segment.in_progress # segment should contain a template render subsegment assert segment.subsegments subsegment = segment.subsegments[0] assert subsegment.name assert subsegment.namespace == 'local' assert not subsegment.in_progress
Example #22
Source File: youtube-dl-server.py From youtube-dl-nas with MIT License | 5 votes |
def dl_queue_list(): with open('Auth.json') as data_file: data = json.load(data_file) userNm = request.get_cookie("account", secret="34y823423b23b4234#$@$@#be") print("CHK : ", userNm) if (userNm == data["MY_ID"]): return template("./static/template/index.tpl", userNm=userNm) else: print("no cookie or fail login") redirect("/")
Example #23
Source File: youtube-dl-server.py From youtube-dl-nas with MIT License | 5 votes |
def dl_queue_login(): with open('Auth.json') as data_file: data = json.load(data_file) # Auth info, when docker run making file req_id = request.forms.get("id") req_pw = request.forms.get("myPw") if (req_id == data["MY_ID"] and req_pw == data["MY_PW"]): response.set_cookie("account", req_id, secret="34y823423b23b4234#$@$@#be") redirect("/youtube-dl") else: return template("./static/template/login.tpl", msg="id or password is not correct")
Example #24
Source File: youtube-dl-server.py From youtube-dl-nas with MIT License | 5 votes |
def dl_queue_list(): return template("./static/template/login.tpl", msg="")
Example #25
Source File: memvisu.py From scat with MIT License | 5 votes |
def index(self): return bottle.template(self.__path["root"] + "index.html")
Example #26
Source File: server.py From deepspeech-websocket-server with Mozilla Public License 2.0 | 5 votes |
def index(): return template('index')
Example #27
Source File: app.py From GNIBappointments with MIT License | 5 votes |
def home(): """handles heroku webpage""" diff = update_appointments() return template( 'heroku_webapp/views/index', gnib_appointments=gnib_appointments, visa_appointments=visa_appointments, last_checked=diff.seconds // 60)
Example #28
Source File: app.py From GNIBappointments with MIT License | 5 votes |
def privacy_policy(): return template('heroku_webapp/views/privacy_policy.tpl')
Example #29
Source File: shockpot.py From shockpot with GNU Lesser General Public License v2.1 | 5 votes |
def func(**kwargs): template_config = dict([(name[9:], value) for name, value in app.config.items() if name.startswith("template.")]) log_request(get_request_record()) response.set_header('Server', app.config['headers.server']) return bottle.template(page_template, **template_config)
Example #30
Source File: app.py From gpuview with MIT License | 5 votes |
def index(): gpustats = core.all_gpustats() now = datetime.now().strftime('Updated at %Y-%m-%d %H-%M-%S') return template('index', gpustats=gpustats, update_time=now)