V
V
vladibuyanov2021-03-22 14:16:51
Flask
vladibuyanov, 2021-03-22 14:16:51

How to get rid of Internal Server Error when deploying to pythonanywhere?

Please help me fix the Internal Server Error when deploying to pythonanywhere.
When run on the local server everything works. This is where errors occur.
I used the instruction:
https://ichi.pro/ru/kak-besplatno-razmestit-priloz...

In the error log it says:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: item
[SQL: SELECT item. id AS item_id, item.title AS item_title, item.price AS item_price, item.about AS item_about, item.size AS item_size, item.src AS item_src, item.link AS item_link, item."isActive" AS "item_isActive"
FROM item]

Code

from flask import render_template, request, redirect
from flask import Flask
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///shop.db '
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)


class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), nullable=False)
    price = db.Column(db.String(5), nullable=False)
    about = db.Column(db.Text, nullable=False)
    size = db.Column(db.String(50), nullable=False)
    src = db.Column(db.Text, nullable=False)
    link = db.Column(db.Text, nullable=False)
    isActive = db.Column(db.Boolean, nullable=True)

    def __repr__(self):
        return self.title


@app.route('/')
@app.route('/index', methods=['GET', 'POST'])
def index_test():
    items = Item.query.all()  # Можно добавить сортировку .order_by(Item.name).
    return render_template('index.html', db=items)


@app.route('/create', methods=['GET', 'POST'])
def create():
    if request.method == "POST":
        title = request.form['title']
        price = request.form['price']
        about = request.form['about']
        size = request.form['size']
        src = request.form['src']
        link = request.form['link']

        item = Item(
            title=title, 
            price=price, 
            about=about, 
            size=size, 
            src=src, 
            link=link)

        try:
            db.session.add(item)
            db.session.commit()
            return redirect('/index')

        except Warning:
            return "Something is going wrong"

    else:
        return render_template('create.html')


@app.route('/about_us', methods=['GET', 'POST'])
def about_us():
    return render_template('about.html')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2021-03-22
@vladibuyanov

no such table:
check if there is a table, if there is - the path to the base is absolute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question