0

次のpython/htmlスクリプトでログアウトボタンまたは再起動ボタンをクリックするときに、確認ボックスを追加する必要があります。このスクリプトは、大きなスクリプトの要約であり、私にとっては問題なく機能します。何か提案がありますか?

前もって感謝します。

#!/usr/bin/python

import cherrypy
import os.path
import struct
from auth import AuthController, require, member_of, name_is
import subprocess
import commands

class Server(object):
    led_logout=0 
    led_restart=0
    _cp_config = {
    'tools.sessions.on': True,
    'tools.auth.on': True
    }   
    auth = AuthController()      
    @cherrypy.expose
    @require()
    def index(self,logout='', restart=''):

    html = """
     <html>
      <head>
      </head>
          <body>
        <p>{htmlText} 
        <p>
        <a href="?logout=1"><img src="images/Logout.png"><a href="?restart=1"><img src="images/Restart.png"></a>
        </ul>
          </body>
     </html>    
           """
    myText = ''
    myText = "Hello"

    if logout:
        self.led_logout = int(logout)             
    if self.led_logout:
        print "Logout !!!!!"
        AuthController().logout('/?logout=0')

    if restart:
        self.led_restart = int(restart)
        #subprocess.call(['sudo shutdown -r now'], shell=True)
        myText = "The system is restarting"

    return html.format(htmlText=myText)
    index.exposed = True

#configuration
conf = {
    'global' : { 
        'server.socket_host': '0.0.0.0', #0.0.0.0 or specific IP
        'server.socket_port': 8085 #server port
    },

    '/images': { #images served as static files
        'tools.staticdir.on': True,
        'tools.staticdir.dir': os.path.abspath('/home/ubuntu/webserver/images')
    }
    }
cherrypy.quickstart(Server(), config=conf)
4

1 に答える 1

0

OK私は解決策を得ました、私はちょうど追加しました

onclick="return confirm('Are you sure you want to logout?');"

したがって、完全な行は次のようになります。

<a href="?logout=1" onclick="return confirm('Are you sure you want to logout?');"><img src="images/Logout.png"><a href="?restart=1" onclick="return confirm('Are you sure you want to restart?');" ><img src="images/Restart.png"></a>
于 2013-01-20T13:57:04.230 に答える