0

我正在尝试为我正在开发的网站加载天气插件。天气插件是一个单独的weather.py 文件,位于/var/www/piss/plugins/base/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 知道这一点pwdhtml1并且currentWeather来自weather你从weather模块中导入的类。我也不确定print类中的语句是否在做你认为他们正在做的事情,考虑到它们在类主体中,而不是方法中。

总而言之,我建议您选择一个更健全的模板系统。Django 的模板,Mako,Jinja,除了 PSP 之外的任何东西。

于 2010-05-03T13:22:11.417 回答