Не удается получить доступ к частям импортированных.PY в.PSP
Я пытаюсь загрузить плагин погоды для сайта, над которым я работаю. Плагин погоды - это отдельный файл weather.py, расположенный по адресу /var/www/piss/plugins/base/weather.py. В PSP он, кажется, импортируется правильно, но я не могу получить доступ к каким-либо переменным или объектам из плагина weather.py в PSP. Вот код, который у меня есть:
...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>"
1 ответ
PSP не особенно популярен в мире Python, и на то есть веские причины. Практически любая другая система шаблонов - лучший выбор. Прошло очень много времени с тех пор, как я смотрел на PSP, и, возможно, я неправильно помню, как он работает, но я не уверен, что вы ожидаете, что PSP узнает об этом. pwd
, html1
а также currentWeather
исходить из weather
класс, который вы импортировали из weather
модуль. Я также не уверен print
операторы в классе делают то, что, по вашему мнению, они делают, учитывая, что они находятся в теле класса, а не в методе.
В общем, я бы предложил вам выбрать более разумную систему шаблонов. Шаблоны Джанго, Мако, Джинджа, все что угодно, кроме PSP.