我经常收到这个错误:浏览器(或代理)发送的请求服务器无法理解
我刚开始学习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>
有没有人能帮我修复这个错误,让我的代码能够运行呢?
1 个回答
-1
这个错误信息:“浏览器(或代理)发送了一个服务器无法理解的请求”通常发生在你用https请求一个http服务器,或者用http请求一个https服务器的时候。你需要检查一下你的网络服务器设置。我猜你可能是在443端口上运行http。