Seite 1 von 1

Bottle-Server Autostart

Verfasst: Montag 27. Februar 2017, 18:10
von djevil
Hallo,
ich habe diesen kleinen Server:

Code: Alles auswählen

@route('/html/<filename>')
def server_static(filename):
    return static_file(filename, root='/home/xsu/.launcher/html')


## as GET
@route('/index')
def index():
    id2 = request.query.id1
    page2 = request.query.page1
    print(id2)
    try:
        subprocess.run([id2])
    except Exception as e:
        print(e)
        
    return template('./cols2.html', id1=id2, page=page2)


run(host='localhost', port=8000, reloader=True)
Das Problem ist, das ich den Server nur im selben Verzeichnis starten kann, sonst findet er die HTML Datei nicht.

Ich möchte den Server gerne automatisch starten, z.B in der .xinitrc (Ubuntu)
Ein:

Code: Alles auswählen

python3 home/xsu/.launcher/server.py
sowie:
ln -s
funktionieren nicht.
Wie kann das gehen?

Mfg d

Re: Bottle-Server Autostart

Verfasst: Montag 27. Februar 2017, 18:27
von __deets__
Ich mache das so (Ausschnitt aus produktivem Code, mag fehlerhaft sein wei zusammengedampft):

Code: Alles auswählen

import os
import sys
import json
import time
import platform
import threading
import tempfile
import subprocess
import argparse

from bottle import (
    app,
    run,
    view,
    static_file,
    request,
    abort,
    TEMPLATE_PATH,
)


TEMPLATE_PATH.append(os.path.join(os.path.dirname(__file__), "views"))
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static")

APP = app()
route = APP.route

@route("/")
@view("index")
def index():
    return dict()

@route('/static/<filename:path>')
def send_static(filename):
    return static_file(filename, root=STATIC_DIR)

Re: Bottle-Server Autostart

Verfasst: Montag 27. Februar 2017, 19:50
von djevil
Super, geht!

Jetzt hätte ich nur noch 2 kleine Probleme:

Wie kann ich Leerzeichen in der URI escapen?
(+ und %20 gehen nicht)

Und: kann ich auch mit:

Code: Alles auswählen

run(host='localhost', port=8080, reloader=True)
irgendwie die CSS etc. automatisch neu laden?

Mfg d

Re: Bottle-Server Autostart

Verfasst: Montag 27. Februar 2017, 21:04
von djevil
Ach, lag nicht an der URI sondern an der der Funktion...

und:
debug statt reloader...