当我运行.py代码时,它将引发错误“ AttributeError:'SQLAlchemy'对象没有属性'integer' “和代码中的'db'会出现红线。第14行会引发错误。
from datetime import datetime
from flask import Flask, render_template, url_for,flash,redirect
from flask_sqlalchemy import SQLAlchemy
from forms import RegistrationForm, LoginForm
app = Flask(__name__) #name of the module
app.config['SECRET_KEY']= 'b2ffa54db1c495dab1f21973b39c400a'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
class User(db.Model):
id = db.column(db.integer, primary_key=True)
username = db.column(db.string(25), unique=True,
nullable=False)
email = db.column(db.string(100), unique=True, nullable=False)
password = db.column(db.string(100), unique=True,
nullable=False)
image_file = db.column(db.string(20), nullable=False,
default='default.jpg')
posts = db.relationship('Post', backreff='author', lazy=True)
def __repr__(self):
return f"user('{self.username}','{self.email}', '{self.image_file}')"
class Post(db.Model):
id = db.column(db.integer, primary_key=True)
title = db.column(db.String(120), nullable=False)
date_posted = db.column(db.DateTime, nullable=False, default=datetime.utcnow)
content = db.column(db.Text, nullable=False)
def __repr__(self):
return f"post('{self.title}','{self.date_posted}')"
答案 0 :(得分:0)
您需要将首字母大写:
<?php
//string 1
$text1 = '[04:38:41] Preflight started, flying offline';
preg_match('/\\[([^\\]]*)\\]/', $text1, $match);
$time1 = $match[1]; // will return 04:38:41
//string 2
$text2 = '[04:39:29] Pushing back with 7512 kg of fuel';
preg_match('/\\[([^\\]]*)\\]/', $text2, $match);
$time2 = $match[1]; // will return 04:39:29
// check difference
$diff = abs(strtotime($time2) - strtotime($time1));
echo $diff; // will return 48 seconds
?>
这应该为您工作。请注意,您必须对定义的所有数据类型执行此操作,否则将对所有数据类型抛出id = db.column(db.Integer, primary_key=True)
:
AttributeError