Today we will update settings page to view config values.

config.py

We update TelegramConfig methods to @classmethod for more convenient. We can call the method directly without a need to create an instance of that class. (Read More)

class TelegramConfig(Config):
  @classmethod
  def get_telgram_token(self):
    return self.get(TELEGRAM_BOT_TOKEN_KEY)

  @classmethod
  def get_base_url(self):
    token = self.get(TELEGRAM_BOT_TOKEN_KEY)
    return 'https://api.telegram.org/bot{}'.format(token)

settings.html

Add a separator and a form-group to view config values

{% extends "base.html" %}

{% set active_page = "settings" %}

{% block main_content %}
<h1 class="mt-5">Settings</h1>
<form action="" method="post">
  {% if message %}
  <div class="alert alert-{{ message["category"] }} alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <strong>{{ message["title"] }}</strong> {{ message["text"] }}
  </div>
  {% endif %}
  <div class="form-group">
    <label for="webhook_url">Webhook URL:</label>
    <input type="url" class="form-control" name="webhook_url" id="webhook_url" value="{{ webhook_url_value }}">
  </div>
  <button type="submit" class="btn btn-primary">Update</button>
  <hr/>
  <div class="form-group">
    <label for="telegram_token">Telegram Token:</label>
    <input type="text" class="form-control" name="telegram_token" id="telegram_token" value="{{ telegram_token_value }}">
  </div>
</form>
{% endblock main_content %}

base.py

[...]

class SettingsPage(Handler):
  @__admin_required
  def get(self):
    kwargs = {
        'title': 'Settings',
    }
    kwargs['webhook_url_value'] = self.__get_webhook_url()
    kwargs['telegram_token_value'] = TelegramConfig.get_telgram_token()
    self.render_template('settings.html', **kwargs)

[...]

Result

Settings Page