I am having a problem with what should be the basic concept in cherrypy, but so far I have not been able to find a tutorial or an example on how to do this (I am new to Cherrypy, be careful).
Problem. (This is a test part, therefore, the lack of reliable authentication and sessions in the code)
The user goes to the index.html page, which is the login page in which the data is indicated and if the data does not match what is in the file, the error message is returned and displayed. It works! If the data is correct, another html file (network.html) is displayed for the user. This is a bit that I canβt get.
The current file system looks like this: -
AppFolder - main.py (main CherryPy file) - media (folder) - css (folder) - js (folder) - index.html - network.html
The layout of the files seems to be correct, since I can access index.html. The code is as follows: (I have a comment where I try to return a new page)
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"
Any help or guidance in this matter would be greatly appreciated.
Greetings
Chris
python cherrypy web-applications
Lipwig
source share