在flask-peewee中创建一个应用程序

时间:2013-10-17 09:27:22

标签: python error-handling flask peewee

我在flask-peewee中创建一个应用程序,用于用户登录,注册和注销。所有的应用程序都在网址上正确路由。当我尝试发布数据而不是给出错误时会发生问题: -
服务器遇到内部错误,无法完成您的请求。服务器过载或应用程序中存在错误。 还会给出一个TypeError:'dict'对象不可调用。

在view.py: -

from flask import request, redirect, url_for, render_template, flash
from flask_peewee.utils import get_object_or_404, object_list
from app import app
from models import User
from auth import *


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

    if request.method == 'POST' and request.form['username']:
        try:
            user = User.select().where(User.username==request.form['username']).get()
            flash('That username is already taken')
        except User.DoesNotExist:       
            user = User(
                username = request.form['username'],
                email = request.form['email'] )
            user.set_password(request.form['password'] )
            user.save()
            auth.login_user(user)
            return 'dua me yaad rakhna'
#           return render_template('home')
#   else:
#       return 'HAAN G DEKHYa fer'

    return render_template("join.html")

在models.py上: -

from hashlib import md5, sha1
import datetime

from flask_peewee.auth import BaseUser
from peewee import *
from app import db



class User(BaseUser):
    username = CharField()
    password = CharField()
    email = CharField()


    class Meta:
        order_by = ('username',) 

main.py: -

from views import *
from app import app
from auth import *



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

app.py: -

from flask import Flask
from flask_peewee.db import Database

app = Flask(__name__)
app.config.from_object('config.Configuration')

db = Database(app)


def create_tables():
    User.create_table()

还定义了route.py和auth.py,但它无法显示任何输出。发生错误。

0 个答案:

没有答案