【发布时间】:2014-11-13 11:29:52
【问题描述】:
我有一个出现此错误的 Flask 应用程序:
ImportError: No module named annotaria, referer: http://ltw1413.web.cs.unibo.it/
所以,我在网络服务器中的根是:
/home/web/ltw1413/html
在我的 html 文件夹中:
- 一个名为“annotaria”的文件夹
- 一个名为“wsgi.wsgi”的文件 .wsgi
我的文件 .wsgi 是:
import sys
sys.path.insert(0, '/home/web/ltw1413/html')
from annotaria import app as application
在我的文件夹“annotaria”中,我有:
- “静态”文件夹:在样式表和 js 中
- “模板”文件夹:在 html 中
- “run.py”:我有我的应用程序的文件 python
run.py 是这样的:
from pydoc import html
from annotaria import app
from flask import Flask, render_template, redirect, request
import json
import urllib2
import urlparse
import re
import string
import os
from SPARQLWrapper import SPARQLWrapper, JSON
from rdflib import Graph, BNode, Literal, Namespace
from time import strftime
import urllib2
import BeautifulSoup
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/index.html')
def reloader():
return render_template('index.html')
# other app.route()...
if __name__ == '__main__':
app.run(debug=True)
如何找到解决方案?我的错误在哪里?
【问题讨论】:
-
你在 annotaria 文件夹中有一个
__init__.py? -
不,我没有!只有 run.py 里面有视图!是错误吗?
-
为了使文件夹成为 Python 包,您必须添加
__init__.py。它可以是空的。之后,您将能够从那里导入。