Re: Static URL in cherrypy

Stefan Krüger <[email protected]>
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
Hi SuperTwister,

have a look at
Tutorial 2: Different URLs lead to different functions 
<http://docs.cherrypy.org/en/latest/tutorials.html#id4> if you modifie the 
example as this:

import random
import string

import cherrypy

class MyHome(object):
    @cherrypy.expose
    def index(self):
        raise cherrypy.HTTPRedirect("/home")

    @cherrypy.expose
    def home(self):
        return "hello world"

if __name__ == '__main__':
    cherrypy.quickstart(MyHome())


you should get to the home path every time you try to access your route.

to server static things have a look at 
Static content serving - Serving a whole directory 
<http://docs.cherrypy.org/en/latest/basics.html#serving-a-whole-directory>

iam using something like this for my static things:
.......

dir_current = os.path.dirname(os.path.abspath(__file__))

......

class StaticFiles(object):

    """only there to have a class..."""

    pass
    # _cp_config = {
    #     'tools.staticdir.on': True,
    #     # 'tools.staticdir.root': dir_static,
    #     # 'tools.staticdir.dir': '',
    #     'tools.staticdir.index' : 'index.html'
    # }
#


....

# config static tool
    dir_static = os.path.join(dir_current, 'static')
    configStatic = {
        '/': {
            'tools.staticdir.on': True,
            'tools.staticdir.root': dir_static,
            'tools.staticdir.dir': '',
            'tools.staticdir.index': 'index.html'
        },
    }

    cherrypy.tree.mount(StaticFiles(), '', configStatic)

....

    # start cherrypy
    print('')
    print('******************************************')
    print('')
    print('cherrypy server - start engine:')
    cherrypy.engine.start()
    cherrypy.engine.block()


eventually that helps you?!

sunny greetings
stefan


On Tuesday, December 8, 2015 at 2:06:40 PM UTC+1, SuperTwister wrote:
>
> My web site works with a cherrypy server, and HTML/JS client. I want that 
> that my website will have a static link, so no matter which page will be 
> visited, the URL on the browser will be stay the same.
>
> Currently the link is:
>
> /static/index.html
>
> I want that the link will be:
>
> /home
>
> Here is the website configuration:
>
> class Root(object):
>     def __init__(self, target):
>         self.target_server = target
>
>  cherrypy.quickstart(webapp, '/', conf)
>
> I have tried to change cherrypy.quickstart(webapp, '/', conf) to cherrypy.quickstart(webapp, 
> '/home', conf), but it's just changed the link to /home/static/index.html.
>
> Any idea?
>
>

-- 
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at http://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.