Deploy Flask-Mdict

I was trying to deploy flask-Mdict (https://github.com/liuyug/flask-mdict) to www.pythonanywhere.com (this site offers hosting for free). Unfortunately, I got error(http://james2021.pythonanywhere.com/). I am so sad :cold_sweat:.
app.py:

#!/usr/bin/env python3
# -*- encoding:utf-8 -*-
import os
import logging

from flask import Flask, redirect, url_for

from flask_mdict import __version__, init_app, mdict_query2


logger = logging.getLogger(__name__)


def create_app(mdict_dir='content'):
    logging.basicConfig(
        level=20,
        format='%(message)s',
    )
    mdict_dir = os.path.realpath(mdict_dir)

    app = Flask(__name__, template_folder=None, static_folder=None)
    app.config['MDICT_DIR'] = mdict_dir
    app.config['MDICT_CACHE'] = False
    app.config['SECRET_KEY'] = "21ffjfdlsafj2ofjaslfjdsaf"
    app.config['APP_DB'] = os.path.join(mdict_dir, 'flask_mdict.db')
    app.config['WFD_DB'] = os.path.join(mdict_dir, 'ecdict_wfd.db')
    app.config['INDEX_DIR'] = None
    app.config['APP_NAME'] = 'Flask Mdict'

    init_app(app, url_prefix='/')
    logger.info(' * app db: %s' % app.config['APP_DB'])

    wfd_db = app.config['WFD_DB']
    if os.path.exists(wfd_db):
        logger.info(f' * Word Frequency Database: {wfd_db}"')
    else:
        logger.error(' * Could not found "Word Frequency Database - {wfd_db}"!')

    @app.route('/favicon.ico')
    def favicon():
        return redirect(url_for('mdict.static', filename='logo.ico'))

    return app

wsgi.py:

# This file contains the WSGI configuration required to serve up your
# web application at http://<your-username>.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Flask project

import sys

# add your project directory to the sys.path
project_home = '/home/James2021/mysite'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from main import create_app
application = create_app()

error:

***************************************************
2021-10-18 23:51:22,089: Error running WSGI application
2021-10-18 23:51:22,092: sqlite3.OperationalError: unable to open database file
2021-10-18 23:51:22,093:   File "/var/www/james2021_pythonanywhere_com_wsgi.py", line 17, in <module>
2021-10-18 23:51:22,093:     application = create_app()
2021-10-18 23:51:22,093: 
2021-10-18 23:51:22,093:   File "/home/James2021/mysite/main.py", line 30, in create_app
2021-10-18 23:51:22,094:     init_app(app, url_prefix='/')
2021-10-18 23:51:22,094: 
2021-10-18 23:51:22,094:   File "/home/James2021/mysite/flask_mdict/__init__.py", line 44, in init_app
2021-10-18 23:51:22,094:     helper.init_flask_mdict()
2021-10-18 23:51:22,094: 
2021-10-18 23:51:22,095:   File "/home/James2021/mysite/flask_mdict/helper.py", line 141, in init_flask_mdict
2021-10-18 23:51:22,095:     db = sqlite3.connect(db_name)
2021-10-18 23:51:22,095: ***************************************************
2021-10-18 23:51:22,095: If you're seeing an import error and don't know why,
2021-10-18 23:51:22,095: we have a dedicated help page to help you debug: 
2021-10-18 23:51:22,096: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-10-18 23:51:22,096: ***************************************************
1 个赞