Ma wieder n paar Probleme mit CherryPy :'(

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
EnTeQuAk
User
Beiträge: 986
Registriert: Freitag 21. Juli 2006, 15:03
Wohnort: Berlin
Kontaktdaten:

Ma schaun, ob ihr mir wiedermal helfen könnt ;)


Ich habe ein kleines Problem mit Statischem Content bei CP 3.

Funktionieren tut es... aber net so, wie es soll ;)

Folgendes funktioniert z.B. wunderbar:

Code: Alles auswählen

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import cherrypy, os, sys
from utils import render_to_response

class Root(object):
    def index(self):
        return render_to_response('index.txt')
    index.exposed = True

root = Root()

cherrypy.tree.mount(root)

if __name__ == '__main__':
    current_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {
        '/style.css': {
                 'tools.staticfile.on': True,
                 'tools.staticfile.filename': os.path.join(current_dir, 'templates', 'style.css')
                }
    }
    ##cherrypy.config.update(os.path.join(current_dir, 'test.conf'))
    cherrypy.quickstart(root, '/', config=conf)
Folgendes dagegen NICHT:

Code: Alles auswählen

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import cherrypy, os, sys
from utils import render_to_response

class Root(object):
    def index(self):
        return render_to_response('index.txt')
    index.exposed = True

root = Root()

cherrypy.tree.mount(root)

if __name__ == '__main__':
    current_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {
        '/style.css': {
                 'tools.staticfile.on': True,
                 'tools.staticfile.filename': os.path.join(current_dir, 'templates', 'style.css')
                }
    }
    cherrypy.config.update(conf)
    cherrypy.server.quickstart()
    cherrypy.engine.start()
Die Änderung befindet sich unten, bei der Deklaration, der Configuration.
Oberes funktioniert ja einwandfrei ... aber letzteres sollte laut Doku (oder hab ich falsch gelesen) auch funktionieren... Tut es aber nicht :'( Er "mounted" jedenfalls '/style.css' nicht richtig bzw. gar nicht.


MfG EnTeQuAk
EnTeQuAk
User
Beiträge: 986
Registriert: Freitag 21. Juli 2006, 15:03
Wohnort: Berlin
Kontaktdaten:

Lösung gefunden ;)

So schauts nu aus:
(der relevante Teil)

Code: Alles auswählen

def setup_standalone_server():
    """Start with the builtin server."""
    cherrypy.config.update({'log.screen': True,
                            'environment': 'production',
                            })

    conf = {
        '/style.css': {
            'tools.staticfile.on': True,
            'tools.staticfile.filename': os.path.join(current_dir, 'templates', 'style.css')
        },
        '/images': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.join(current_dir, 'templates', 'images')
        }
    }

    cherrypy.tree.mount(root, config=conf)
    cherrypy.server.quickstart()
    cherrypy.engine.start()


if __name__ == "__main__":
    setup_standalone_server()
MfG EnTeQuAk
Antworten