次のような構造の template という名前のフォルダーからインポートしようとしています
controller/
/__init__.py
/login.py # <- I'm here
template/
/__init__.py # from template import *
/template.py # contains class Template
pythonは必要なクラスを確認できるようですが、インポートに失敗します。これはlogin.pyコードです
import webapp2
import template
class Login(webapp2.RequestHandler):
#class Login(template.Template):
def get(self):
self.response.out.write(dir(template))
版画
['Template', 'Users', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', 'jinja2', 'os', 'template', 'urllib', 'webapp2']
輸入ラインの切り替え
import webapp2
import template
#class Login(webapp2.RequestHandler):
class Login(template.Template):
def get(self):
self.response.out.write(dir(template))
版画
class Login(template.Template):
AttributeError: 'module' object has no attribute 'Template'
私は何を間違っていますか?ありがとう
編集: index という名前の別のフォルダーを作成しました
index/
/__init__.py # from index import *
/index.py # class Index
/index.html
index.py 内のコードは
from template import Template
class Index(Template):
def get(self):
self.render("/index/index.html")
このコードはエラーなしで機能しましたが、1 つのインデックス コントローラー フォルダーでエラーが発生しました