(sqlite3.OperationalError)没有这样的表:blog_table [SQL:'SELECT blog_table.title AS blog_table_title,blog_table

时间:2019-05-09 13:42:39

标签: python sqlalchemy flask-sqlalchemy

我想将数据库中的所有数据显示到另一个页面。我是保温瓶的新手,从两天开始就陷入了这个问题,任何了解保温瓶的人都请帮助我。

这是我项目的一些代码

app / models.py



class BlogTable(db.Model):
     title = db.Column(db.String(200),primary_key=True)
     description = db.Column(db.String(300))

     def __repr__(self):
        return '<BlogPost {}>'.format(self.title)

app \ main \ forms.py



class BlogTable(db.Model):
     title = db.Column(db.String(200),primary_key=True)
     description = db.Column(db.String(300))

     def __repr__(self):
        return '<BlogPost {}>'.format(self.title)

app \ main \ routes.py


#----admin dashborad----
@bp.route('/admin/dashboard', methods=['GET', 'POST'])
@login_required
def dashboard():
    blogs = BlogTable.query.all()
    return render_template('dashboard.html',name=current_user.username, blogs=blogs)


#---admin post---#
@bp.route('/admin/posts',methods=['GET','POST'])
@login_required
def posts():
    form = BlogForm()
    if form.validate_on_submit():
        post = BlogTable(title=form.title.data, description=form.description.data)
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('main.dashboard'))
    return render_template('posts.html',title='Blogs', form=form )

app / templates / posts.html

{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block body %}
    <form action="" method="post">
         {{ form.hidden_tag() }}
        <p>
            {{form.title.label}}<br>
            {{form.title(size=32)}}
        </p>
        <p>
            {{form.description.label}}
            {{form.description(size=32)}}
        </p>
        <p> {{form.submit()}}</p>
    </form>

{% endblock %}

app / templates / dashboard.html


{% extends "base.html" %}

{% block content %}
    <h1>Hi, {{ current_user.username }}!</h1>
     {% for blog in blogs %}
    <p>
        {{blog.title}} <b> {{blog.description}}
    </p>
    {% endfor %}
{% endblock %}

错误

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: blog_table [SQL: 'SELECT blog_table.title AS blog_table_title, blog_table.description AS blog_table_description \nFROM blog_table']

我要显示用户在张贴到仪表板页面的帖子页面中提交的所有标题和描述

0 个答案:

没有答案