码迷,mamicode.com
首页 > 编程语言 > 详细

Python之Flak入门

时间:2018-12-22 22:06:54      阅读:413      评论:0      收藏:0      [点我收藏+]

标签:inter   turn   pytho   family   div   size   sheet   src   none   

文件名vsearch4web

from flask import Flask, render_template, request
from vsearch import search4letters

app = Flask(__name__)

@app.route(/search4, methods=[POST])
def do_search() -> html:
    phrase = request.form[phrase]
    letters = request.form[letters]
    title = Here are your results:
    results = str(search4letters(phrase, letters))
    return render_template(results.html,
                           the_phrase=phrase,
                           theletters=letters,
                           the_thtle=title,
                           the_results=results)


@app.route(/)
@app.route(/entry, methods=[GET, POST])
def entry_page() -> html:
    return render_template(entry.html, the_title=Welcome to search4letters ont the web!)

app.run

文件名vsearch

def search4vowels(phrase: str) -> set:
    """Return any vowels found in a supplied phrase."""
    vowels = set(aeiou)
    return vowels.intersection(set(phrase))


def search4letters(phrase: str, letters: str=aeiou) -> set:
    """Return any vowels found in a supplied phrase."""
    return set(letters).intersection(set(phrase))

在temolates中的三个html文件

  results

{% extends base.html %}
{% block body %}
    <h2>{{ the_title }}</h2>
    <p>You submitted the following Date:</p>
    <table>
        <tr>
            <td>Phrase:</td>
            <td>{{ the_phrase }}</td>
        </tr>
        <tr>
            <td>Letter:</td>
            <td>{{ the_letters }}</td>
        </tr>
    </table>
    <p>When "{{ the_phrase }}" is search for "{{ the_letters }}",the following results are returned:</p>
    <h3>{{ the_results }}</h3>
{% endblock %}

  entry

{% extends base.html %}

{% block body %}

    <h2>{{ the_title }}</h2>

    <form method=POST action=/search4>
        <table>
            <p>Use this form to submit a search request:</p>
            <tr>
                <td>Phrase:</td>
                <td><input name=phrase type=TEXT width=60></td>
            </tr>
            <tr>
                <td>Letters:</td>
                <td><input name=letters type=TEXT value=aeiou></td>
            </tr>
        </table>
        <p>When youre ready, click this button:</p>
        <p><input value=Do it! type=SUBMIT></p>
        <p><input value="Do it!" type="SUBMIT"></p>
    </form>

{% endblock %}

  base

  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ the_title }}</title>
    <link rel="stylesheet" href="static/hf.css"/>
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>

在static中的css样式

  hf

  

技术分享图片
body {
  font-family:      Verdana, Geneva, Arial, sans-serif;
  font-size:        medium;
  background-color: tan;
  margin-top:       5%;
  margin-bottom:    5%;
  margin-left:      10%;
  margin-right:     10%;
  border:           1px dotted gray;
  padding:          10px 10px 10px 10px;
}
a {
  text-decoration:  none; 
  font-weight:      600; 
}
a:hover {
  text-decoration:  underline;
}
a img {
  border:           0;
}
h2 {
  font-size:        150%;
}
table {
  margin-left:      20px;
  margin-right:     20px;
  caption-side:     bottom;
  border-collapse:  collapse;
}
td, th {
  padding:          5px;
  text-align:       left;
}
.copyright {
  font-size:        75%;
  font-style:       italic;
}
.slogan {
  font-size:        75%;
  font-style:       italic;
}
.confirmentry {
  font-weight:      600; 
}

/*** Tables ***/

table {
font-size:          1em;
background-color:   #fafcff;
border:             1px solid #909090;
color:              #2a2a2a;
padding:            5px 5px 2px;
border-collapse:    collapse;
}

td, th {
border:             thin dotted gray;
}

/*** Inputs ***/
input[type=text] {
  font-size:        115%;
  width:            30em;
}
input[type=submit] {
  font-size:        125%;
}
select {
  font-size:        125%;
}
View Code

 

Python之Flak入门

标签:inter   turn   pytho   family   div   size   sheet   src   none   

原文地址:https://www.cnblogs.com/XueYueHua/p/10162350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!