0

作業中の Web サイトに天気プラグインをロードしようとしています。天気プラグインは、/var/www/piss/plugins/base/weather.py にある個別の weather.py ファイルです。PSP では正しくインポートされているようですが、PSP の weather.py プラグインから変数やオブジェクトにアクセスできません。ここに私が持っているコードがあります:

    ...HTML and CSS stuff...

<% 
sys.path.append('/var/www/piss/plugins/base/')
pwd = os.getcwd()
import sys, os
import string
from weather import weather
%>
            <%= pwd %>
            <%= html1 %>
            <%= currentWeather %>
            </div>
        </div>
        <div id="footer">Piss + INK Version                     0.00001</div>
        <div id="bottom"></div>
    </div>
</body>
</html>

これがweather.pyコードです:

from basePlugin import plugin
import MySQLdb
import pywapi

class weather(plugin):
    """
    weather.py
    Built-in weather plugin.
    """
    def __init__(self,zipcode):
        self.zipcode = zipcode

#Tested without DB access
    #db=_mysql.connect(host="localhost",user="things",passwd="things",db="things")
    #zip="SELECT zipcode FROM "+currentUser+"\;"
    #c = db.cursor()
    #dbResult = c.execute (zip)
    wResult=pywapi.get_weather_from_google('05401')
    html1="""
<div class="weather">
Weather:<br />
"""
    print html1
    currently = wResult['current_conditions']
    currentWeather = currently['condition']
    print currentWeather
    print "<br />"

    if currentWeather == "Mostly Cloudy":
        print '<img src="themes/default/images/weather/cloudy.png" alt="cloudy">'

    if currentWeather == "Cloudy":
        print '<img src="themes/default/images/weather/cloudy.png" alt="cloudy">'

    if currentWeather == "Sunny":
        print '<img src="themes/default/images/weather/sunny.png" alt="sunny">'

    if currentWeather == "Showers":
        print '<img src="themes/default/images/weather/rain.png" alt="rain">'

#More conditions will be added in actual plugin.

print "</div>"
4

1 に答える 1

0

PSP は Python の世界ではあまり人気がありませんが、それには正当な理由があります。他のほとんどすべてのテンプレート システムを選択することをお勧めします。PSP を見てからかなり時間が経ちました。どのように動作するかを覚えていないかもしれませんが、PSP がそれを認識しpwd、モジュールからインポートしたクラスhtml1からcurrentWeather取得されると期待しているとは思えません。また、メソッドではなくクラス本体にあることを考えると、クラス内のステートメントがあなたが思っていることを行っているかどうかもわかりません。weatherweatherprint

全体として、より健全なテンプレート システムを選択することをお勧めします。Django のテンプレート、Mako、Jinja、PSP 以外のすべて。

于 2010-05-03T13:22:11.417 に答える