Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added basic form and web server

  • Loading branch information...
commit 9cbaa412d4a6df102c0e20440b04b6c1ba5ea43d 1 parent 753ff48
authored February 05, 2012
47  sps/web/app.py
... ...
@@ -0,0 +1,47 @@
  1
+from flask import Flask, request, session, g, redirect, url_for, \
  2
+     abort, render_template, flash
  3
+
  4
+app = Flask(__name__)
  5
+
  6
+@app.route("/", methods=['GET', 'POST'])
  7
+def hello():
  8
+    if request.method == "POST":
  9
+        return  ( """your name is %s  <br>
  10
+                   your password is %s <br>
  11
+                   your fruits are %s <br>
  12
+                    you're from %s <br>""" % (
  13
+                    request.form['username'], 
  14
+                    request.form['password'],
  15
+                    request.form['foods'],
  16
+                    request.form['continent'] ))
  17
+        # put what they submitted here
  18
+
  19
+    else:
  20
+        return render_template('form.html')
  21
+    
  22
+
  23
+@app.route("/some/other/path/")
  24
+def other_path():
  25
+   return "here you go"
  26
+
  27
+@app.route('/login')
  28
+def login(): 
  29
+    pass
  30
+
  31
+@app.route('/user/test')
  32
+def test():
  33
+    return "it works dfgsdg "
  34
+
  35
+
  36
+@app.route('/user')
  37
+def profile(username): 
  38
+    return "hello"
  39
+
  40
+    with app.test_request_context():
  41
+        print url_for('index')
  42
+        print url_for('login')
  43
+        print url_for('login', next='/')
  44
+        print url_for('profile', username='John Doe')
  45
+
  46
+if __name__ == "__main__":
  47
+    app.run(debug=True)
7  sps/web/app.wsgi
... ...
@@ -0,0 +1,7 @@
  1
+import os
  2
+import sys
  3
+
  4
+sys.path.append('/srv/www/app')
  5
+
  6
+from app import app as application
  7
+
53  sps/web/templates/form.html
... ...
@@ -0,0 +1,53 @@
  1
+<!doctype html>
  2
+<html lang="en">
  3
+<head>
  4
+  <meta charset="utf-8">
  5
+  <title>My Page</title>
  6
+</head>
  7
+
  8
+<body>
  9
+
  10
+  <form action="/" method="POST" name="my_form">
  11
+    <fieldset>
  12
+      <legend align="center">Important Information</legend>vim 
  13
+      <label for="username">Username:</label><br>
  14
+      <input type="text" name="username" id="username"><br>
  15
+      <label for="password">Password:</label><br>
  16
+      <input type="password" name="password" id="password"><br>
  17
+      <input type="radio" name="gender" value="Male" id="male"><label for="male">Male</label><br>
  18
+      <input type="radio" name="gender" value="Female" id="female"><label for="female">Female</label><br>
  19
+      <input type="checkbox" name="foods" value="Grapes" id="grapes"><label for="grapes">Grapes</label><br>
  20
+      <input type="checkbox" name="foods" value="Apples" id="apples"><label for="apples">Apples</label><br>
  21
+      <input type="checkbox" name="foods" value="Bananas" id="bananas"><label for="bananas">Bananas</label>
  22
+    </fieldset>
  23
+    <br>
  24
+    
  25
+    <fieldset>
  26
+      <legend align="center">Optional Items</legend>
  27
+      <label for="essay">We want to know more about you.<br>Write a short essay about yourself!</label><br>
  28
+      <textarea name="essay" id="essay" rows="10" cols="30">
  29
+      </textarea>
  30
+      <br>
  31
+
  32
+      <label for="continent">Where are you from?</label><br>
  33
+      <select name="continent" id="continent">
  34
+        <optgroup label="Americas">
  35
+          <option>North America</option>
  36
+          <option>South America</option>
  37
+        </optgroup>
  38
+        <optgroup label="Eurasia">
  39
+          <option>Europe</option>
  40
+          <option>Asia</option>
  41
+        </optgroup>
  42
+        <option>Africa</option>
  43
+        <option>Australia</option>
  44
+        <option>Antarctica</option>
  45
+      </select>
  46
+    </fieldset>
  47
+    <br>
  48
+  
  49
+    <input type="submit" value="Continue">
  50
+  </form>
  51
+
  52
+</body>
  53
+</html>

0 notes on commit 9cbaa41

Please sign in to comment.
Something went wrong with that request. Please try again.