我经常收到此错误浏览器(或代理)发送此服务器无法理解的请求

时间:2012-01-24 10:12:56

标签: python

我是python的新手,只是尝试非常简单的代码 这是我的代码

------------------- proapp.py

from flask import Flask, render_template, url_for, request, flash, redirect
from flaskext.sqlalchemy import SQLAlchemy
import types

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['DEBUG'] = True
db = SQLAlchemy(app)

class Basics(db.Model):

    __tablename__ = 'basics'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)

    def __init__(self, username):
          self.username = username 

    def __repr__(self):
        return '<User %r>' % self.username

@app.route('/')

def mainlists():
          return render_template('index.html', lists=Basics.query.all())

@app.route('/', methods=['GET', 'POST'])

def createlist():
      if request.method == 'POST':
           new_list = Basics(request.form['lists'])
           db.session.add(new_list)
           db.session.commit()
           flash(u' item was successfully created')
           return redirect(url_for('mainlists'))

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

我的HTML代码就是这样:

<html>
  <head>
      <style> 
         h1
           {
             padding: 0px 0 0 13px;
             margin: 15px 0 15px 0;
             color:black;
             height:17px;
             position:relative
            }
            h2
            {  
              height:17px;
              color:gray  
             }
       </style>
    </head>
       <body background="swirlies.gif">
            <h1><i><b>Memelist</b></i></h1>
               <hr size="3" noshade color="gray">
                 <marquee behavior="alternate"> <h4><i>Share your memories</i></h4></marquee>     
                       <ul>
                          {% for item in lists %}
                          <li>{{ item.username }}</li>
                          {% endfor %}
                      </ul>

                   <form action="{{ url_for('createlist') }}" method=post >

                   <center>  Enter the list<input type="text" value=""/>
              <input type="submit" value="submit"/></center>
          </form>
       </body>
</html>

任何人都可以修复此错误并让我的代码执行

0 个答案:

没有答案