Существует много Python web frameworks. Например, чтобы разбить предложение, используя bottle
:
break-sentence.py
:
#!/usr/bin/env python
from bottle import request, route, run, view
@route('/', method=['GET', 'POST'])
@view('form_template')
def index():
return dict(parts=request.forms.sentence.split(), # split on whitespace
show_form=request.method=='GET') # show form for get requests
run(host='localhost', port=8080)
И файл form_template.tpl
шаблона, который используется как для отображения формы и частей предложения после обработки в Python (см index()
выше функции):
<!DOCTYPE html>
<title>Break up sentence</title>
%if show_form:
<form action="/" method="post">
<label for="sentence">Input a sentence to break up</label>
<input type="text" name="sentence" />
</form>
%else:
Sentence parts:<ol>
%for part in parts:
<li> {{ part }}
%end
</ol>
%end
request.forms.sentence
используется в Python для доступа пользовательского ввода из <input name="sentence"/>
поля.
Чтобы попробовать его, вы можете просто скачать и запустить bottle.py:
$ python break-sentence.py
Bottle server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
Теперь вы можете посетить http://localhost:8080/
.
Вы используете каркас? Код в ваших вопросах действительно поможет вам найти ответ. – sparrow