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.