cherrypyの基本的なコンセプトに問題がありますが、私はチュートリアルやこれを行う方法の例が見つかりませんでした(私はCherrypy初心者です) 。Cherrypyの静的なhtmlファイル
問題。 (これはテストピースなので、認証とセッションはコードでは堅牢ではありません)
ユーザはログインページであるindex.htmlページに移動し、詳細が一致しない場合エラーメッセージが返され、表示されます。これは動作します! 詳細が正しければ、別のhtmlファイルがユーザに表示されます(network.html)これは私が働くことができないビットです。
現在のファイルシステムは次のようになります。 - :(私はどこにコメントを配置ファイルのレイアウトは、私は、コードは次のようになりindex.htmlを にアクセスできるように、右のようです
AppFolder
- main.py (main CherryPy file)
- media (folder)
- css (folder)
- js (folder)
- index.html
- network.html
私は
import cherrypy
import webbrowser
import os
import simplejson
import sys
from backendSystem.database.authentication import SiteAuth
MEDIA_DIR = os.path.join(os.path.abspath("."), u"media")
class LoginPage(object):
@cherrypy.expose
def index(self):
return open(os.path.join(MEDIA_DIR, u'index.html'))
@cherrypy.expose
def request(self, username, password):
print "Debug"
auth = SiteAuth()
print password
if not auth.isAuthorizedUser(username,password):
cherrypy.response.headers['Content-Type'] = 'application/json'
return simplejson.dumps(dict(response ="Invalid username and/or password"))
else:
print "Debug 3"
#return network.html here
class DevicePage(object):
@cherrypy.expose
def index(self):
return open(os.path.join(MEDIA_DIR, u'network.html'))
config = {'/media': {'tools.staticdir.on': True, 'tools.staticdir.dir': MEDIA_DIR, }}
root = LoginPage()
root.network = DevicePage()
# DEVELOPMENT ONLY: Forces the browser to startup, easier for development
def open_page():
webbrowser.open("http://127.0.0.1:8080/")
cherrypy.engine.subscribe('start', open_page)
cherrypy.tree.mount(root, '/', config = config)
cherrypy.engine.start()
この問題で任意の助けや指導をいただければ幸いです)新しいページを返すようにしようとしています
乾杯
クリス
アドバイスをいただきありがとうございました。ありがとうございました。 – Lipwig