Re: Static URL in cherrypy
Stefan Krüger <[email protected]>
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
Hi SuperTwister,
i think your code can't work.
you have a 'webapp' in your quickstart but no place you define it..
pleas do some work on your own:
build a minimal one-file example that is runnable.
you can start with on of the documentation examples:
http://docs.cherrypy.org/en/latest/basics.html?highlight=quickstart#the-one-minute-application-example
(
http://docs.cherrypy.org/en/latest/pkg/cherrypy.html?highlight=quickstart#cherrypy.quickstart
)
and than extend it first so that the basic static serving works. (like in
the documentation)
and if you have this running copy&save it with a new file name and try to
include what you want to achieve.
and than one more thing:
> But it didn't work.
>
says nothing.
Does the script run or is there a startup error?
are there runtime errors?
what is happening when you try to do what you want?
don't get me wrong - i am willing to help - but i have not the time to do
it all for you..
sunny greetings
stefan
On Sunday, December 13, 2015 at 11:52:59 AM UTC+1, SuperTwister wrote:
>
> Hi Stefan Krüger, It's doesn't works.
> I've tried to use
>
> [/static]
> tools.staticdir.on = True
> tools.staticdir.dir = "/home/site/static"
> tools.staticdir.index = "index.html"
>
> But it didn't work.
>
> Please have a look at my code. Do you know what could be the issue?
>
> cherrypy.config.update({
> 'server.socket_port': 9090,
> 'server.socket_host': '0.0.0.0'
> })
> conf = {
> '/': {
> 'tools.sessions.on': True,
> 'tools.staticdir.root': os.path.abspath(os.getcwd())
> },
> '/static': {
> 'tools.staticdir.on': True,
> 'tools.staticdir.dir': './static/html'
> 'tools.staticdir.index': 'index.html'
> },
> '/js': {
> 'tools.staticdir.on': True,
> 'tools.staticdir.dir': './static/js'
> },
> '/css': {
> 'tools.staticdir.on': True,
> 'tools.staticdir.dir': './static/css'
> },
> '/img': {
> 'tools.staticdir.on': True,
> 'tools.staticdir.dir': './static/img'
> },
> '/fonts': {
> 'tools.staticdir.on': True,
> 'tools.staticdir.dir': './static/fonts'
> }
>
>
> }
>
>
> class Root(object):
> def __init__(self, target):
> self.target_server = target
>
>
> @cherrypy.expose
> def index(self):
> raise cherrypy.HTTPRedirect("/static/index.html")
>
>
> cherrypy.quickstart(webapp, '/home', conf)
>
>
>
>
> On Thursday, December 10, 2015 at 3:01:47 PM UTC+2, Stefan Krüger wrote:
>>
>> 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 https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.