Advertisement
slipcell

flask

Apr 19th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. 'layout.html'
  2. <!doctype html>
  3. <title>My Application</title>
  4. {% with messages = get_flashed_messages() %}
  5.   {% if messages %}
  6.     <ul class=flashes>
  7.     {% for message in messages %}
  8.       <li>{{ message }}</li>
  9.     {% endfor %}
  10.     </ul>
  11.   {% endif %}
  12. {% endwith %}
  13. {% block body %}{% endblock %}
  14.  
  15.  
  16. 'login.html'
  17. {% extends "layout.html" %}
  18. {% block body %}
  19.   <h1>Welcome</h1>
  20.   {% if error %}
  21.     <p class=error><strong>Error:</strong> {{ error }}
  22.   {% endif %}
  23.   <form action="" method=post>
  24.     <dl>
  25.       <dt>Enter here:
  26.       <dd><input type=text name=submit value="{{
  27.          request.form.username }}">
  28.   </form>
  29. {% endblock %}
  30.  
  31. 'main.py file'
  32. from flask import Flask, flash, redirect, render_template, \
  33.      request, url_for
  34. import urllib2
  35.  
  36. app = Flask(__name__)
  37. app.secret_key = 'some_secret'
  38.  
  39. @app.route('/', methods=['GET', 'POST'])
  40. def index():
  41.     error = None
  42.     if request.method == 'POST':
  43.         x = request.form['submit']
  44.         x = urllib2.urlopen(x)
  45.         flash(x.read())
  46.  
  47.     return render_template('login.html', error=error)
  48.  
  49. if __name__ == "__main__":
  50.     app.run(debug = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement