Python之Flak入门,pythonflak,文件名vsearch
Python之Flak入门,pythonflak,文件名vsearch
文件名vsearch4web
from flask import Flask, render_template, requestfrom vsearch import search4lettersapp = 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 you‘re 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入门
相关内容
- python2升级python3,,一 python2升
- python--软件目录结构,python--目录结构,软件目录结构规
- Python 有序字典(OrderedDict)与 普通字典(dict),pythonor
- python dataframe slice,,import pan
- python机器学习-sklearn挖掘乳腺癌细胞(五),,python机器
- opencv-python下简单KNN分类识别,opencv-pythonknn,KNN是数据挖
- java-for循环 vs python-for循环,,>>>>>>>&
- 审计系统---堡垒机python下ssh的使用,,堡垒机python下
- python 列表元组加减乘除法,python加减乘除,元组(typle)列
- ubuntu python opencv3 cv2.cv2 has no attribute 'face'
评论关闭