Python 100 project #12: First Website using Flask

This is just a mock web server for starter. I use flask as a web framework for now.

This time, I just implemented the first page(index.html) and the front page for Google Trends application(to show the wordcloud on the web page) only. Actual application will be added in later issue.

Output Example:


Here is the code:

| ... store predefined dictionaries
  | ... functions to generate actual backend data
  | ... classes to define forms
  | ... routing for all directories. serving display
    |-base.html ... header and footer
    |-gtrends_wc.html ... google trends application page
from flask_wtf import FlaskForm

from wtforms import SelectField, SubmitField
from wtforms.validators import DataRequired

from facts import COUNTRYDICT

class CountrySelectForm(FlaskForm):
    countries = [(c[1], c[0]) for c in COUNTRYDICT.items()]
    country = SelectField(label='country', choices=countries, validators=[DataRequired()])
    submit = SubmitField('Generate')
from flask import render_template

from app import app, func
from app.forms import CountrySelectForm
from app.func import *

def index():
    msg = 'Hello World!'

    return render_template('index.html', title='Home', msg=msg)

@app.route('/gtrends_wordcloud', methods=['GET'])
def gen_gtrends_wordcloud():
    form = CountrySelectForm()

    return render_template('gtrends_wc.html', title='Google Trends Wordcloud', form=form)

      {% if title %}
      <title>{{ title }} - Webtest</title>
      {% else %}
      <title>Welcome to Webtest</title>
      {% endif %}
        {% block content %}{% endblock %}
{% extends "base.html" %}

{% block content %}
    <h1>Hello this is just a test website!</h1>
        <p>{{ msg }}</p>
{% endblock %}
{% extends "base.html" %}

{% block content %}
    <h1>Google Trends Wordcloud generator</h1>
    <form action="" method="post">
            {{ }} {{ }}<br>
            {% for error in %}
            <span style="color: red;">[{{ error }}]</span>
            {% endfor %}
        <p>{{ form.submit() }}</p>
{% endblock %}