1

I have a directory structure that looks like this:

project/
    index/
        about.html
        index.html
        forum.html
        profile.html
        settings.html
        apple-touch-icon.png
        static/
            main.css
            forum.css
            main.js
            forum.js
            load-image.min.js
    server.py
    metaclass.py
    mailing.py
    errors.log

I'd like to be able to make cherrypy serve all of these files from index/. However, I also want about.html, index.html, forum.html, profile.html, etc. to be accessible via /about, /, /forum, /profile, etc., so this is not the same as just simple static file serving. Also, I want to have some custom methods, like /login, which needs a GET and POST, and pre-templated user profile pages. How can this be done?

Robert Moore
  • 2,207
  • 4
  • 22
  • 41
  • Possible duplicate of [How to use cherrypy as a web server for static files?](https://stackoverflow.com/questions/759627/how-to-use-cherrypy-as-a-web-server-for-static-files) – Willian Vieira May 08 '18 at 21:09
  • @WillianVieira If you read the post, you will see that I need to access `index.html` as `/` and `about.html` as `/about`. – Robert Moore May 08 '18 at 21:23

1 Answers1

1

Cherrypy is going to recursively serve the files in the index folder. What you are trying to do has more to do with the url path.

In your server.py you can attach the handler for /about.html to achieve what you want.

    @cherrypy.expose
    def about_html(self):
       return open('/index/about.html')

hope this helps!

Andrew Kloos
  • 4,189
  • 4
  • 28
  • 36