내가 플라스크를 사용하여 웹 사이트를 만드는 중이라서 오래되지, 버퍼 및 MySQLdb 아래 나는 다음과 같은 오류를 얻고있다는 문자열 또는 읽기 전용
from flask import Flask,render_template,request,url_for,flash,session
from flask_session import Session
from dbconnect import connection
from wtforms importForm,BooleanField,StringField,TextField,PasswordField,validators,IntegerField
from passlib.hash import sha256_crypt
from MySQLdb import escape_string as thwart
from flask_wtf import Form
from wtforms.validators import InputRequired
import gc
sess=Session()
SESSION_TYPE = 'memcache'
app=Flask(__name__)
@app.route('/')
def test():
return render_template("home.html")
@app.route('/about/')
def about():
return render_template("about.html")
@app.route('/dashbord/')
def dashbord():
return('hello')
@app.route('/contact/')
def contact():
return render_template("contact.html")
@app.route('/login/',methods=['GET','POST'])
def login():
return render_template("login.html")
class RegistrationForm(Form):
username=TextField('username',[validators.Length(min=4,max=20),validators.Required()])
email=TextField('email',[validators.Length(min=6,max=50),validators.Required()])
password=PasswordField('password',[validators.EqualTo('confirm',message="Password must match"),validators.Required()])
confirm=PasswordField("repeat password")
phone_no=IntegerField('phone_no',[validators.Required()])
@app.route("/sign_up",methods=['GET','POST'])
def sign():
try:
form=RegistrationForm(request.form)
if request.method == 'POST':
username=form.username.data
email=form.email.data
password=sha256_crypt.encrypt((str(form.password.data)))
phone_no=form.phone_no.data
c,conn =connection()
x = c.execute("SELECT * FROM customer WHERE username =(%s)",
(username,))
if int(x)>0:
flash("That username is taken")
return render_template('sign.html',form=form)
else:
args="INSERT INTO customer (username,email,password,phone_no) VALUES (%s,%s,%s,%s)",
(thwart(username),thwart(email),thwart(password),thwart(phone_no))
c.execute(*args)
conn.commit()
flash("Thanks for registering")
c.close()
conn.close()
gc.collect()
session['logged_in']=True
session['username']=username
return redirect(url_for('dashbord'))
return render_template("sign.html",form=form)
except Exception as e:
return(str(e))
if __name__=="__main__":
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
sess.init_app(app)
app.run(debug=True)
init.py 내 파이썬 파일입니다한다 옵션 값이있다으로 제출 버튼을 클릭 한 후
는Must be string or read-only buffer, not long
전체 오류 메시지를 제공해 주시겠습니까? –
이것은 내가 얻는 것입니다. TypeError : 긴 문자열이 아니거나 읽기 전용 버퍼 여야합니다. 나는 pone_no @LPK와 관련이 있다고 생각합니다. –
하지만 오류가 나타나는 줄 번호를 얻지 못합니까? –