doubishi8303 2017-12-24 03:32
浏览 42

Python代码和显示与PHP

I have a Python and a PHP program, for a display application in a web browser. This is the PHP code:

<div id="container">
    <h1>Summarizer</h1>

    <form action="." method="post">
        <p>
            <label for="text">Text:</label>
        </p>
        <p>
            <textarea id="text" name="text">{{ text }}</textarea>
        </p>
        <p>
            <label for="number">Number of sentences:
                <input type="number" min="1" value="{{ number }}" name="number" id="number"/>
            </label>
        </p>
        <p>
            <label for="language">Language:
                <select name="language" id="language">
                    % for a_language in available_languages:
                        <option value="{{ a_language }}"{{ " selected" if language == a_language else "" }}>{{ a_language.capitalize() }}</option>
                    % end
                </select>
            </label>
        </p>
        <p>
            <button type="submit" id="submit">Summarize</button>
        </p>
    </form>

    % if result:
    <h2>Result</h2>
    <p>
        {{ result }}
    </p>
    % end
</div>

And this is the Python code:

#!/usr/bin/env python
from bottle import Bottle, request, view
from summarize import summarize

DEMO_TEXT = (
    "Alice and Bob are friends. Alice is fun and cuddly. Bob is cute and"
    " quirky. Together they go on wonderful adventures in the land of"
    " tomorrow. Alice's cuddliness and Bob's cuteness allow them to reach"
    " their goals. But before they get to them, they have to go past their"
    " mortal enemy — Mr. Boredom. He is ugly and mean. They will surely"
    " defeat him. He is no match for their abilities."
)

LANGUAGES = (
    'danish',
    'dutch',
    'english',
    'finnish',
    'french',
    'german',
    'italian',
    'norwegian',
    'portuguese',
    'spanish',
    'swedish',
)

app = Bottle()

@app.route('/', method='GET')
@app.route('/', method='POST')
@view('index')
def index():
    text = request.forms.getunicode('text')
    number = int_or_none(request.forms.get('number'))
    language = request.forms.get('language') or 'english'
    result = summarize(text, number, language) if number and text else None
    return {
        'text': text or DEMO_TEXT,
        'result': result,
        'number': number or 5,
        'language': language,
        'available_languages': LANGUAGES
    }


def int_or_none(value):
    try:
        return int(value)
    except TypeError:
        return None


if __name__ == "__main__":
    app.run()

I have run into a problem. The value in the Python code, can't display in the PHP code. How would I go about fixing this? I am running this code in Windows, and not on Linux. Thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算