我想尝试从web2py
外部编写一些胶子派生的组件(web2py
html helpers)。通过这种方式,我可以在命令行上测试组件,并生成简单的html文件,在将它们与完整的web2py
应用程序堆栈集成之前,我可以分析这些文件。这加快了我的开发周期,因为我可以专注于微调组件的HTML,而不必担心任何其他问题(重新部署、数据库等)。快速而简单:用gluon.html
助手准备一个web2py组件,看看生成的HTML是否好看,然后然后在web2py
内使用它。在
试验基本上是成功的。我只需要:
from gluon.html import A, TABLE, DIV, SPAN, THEAD, TR, TH, TBODY, URL, H1
def T(txt):
return txt
def my_simple_component(title):
return H1(T(title))
def test():
print my_simple_component('Hello')
产生预期输出:
^{pr2}$(我不关心我的测试中的T
。对于我想使用的任何测试URL
,我只需通过一个假的应用程序/控制器/函数。)
我发现的唯一问题是,我需要有一个到web2py
的符号链接,gluon.html
导入才能工作,即使胶子在PYTHONPATH上。在
ln -s /install_dir/web2py/gluon/ .
有没有办法在没有额外链接的情况下导入胶子组件?
考虑到在测试阶段,我的组件在web2py应用程序树之外。在
这是我得到的错误:
Traceback (most recent call last):
File "lib_test1.py", line 4, in <module>
from gluon.html import A, TABLE, DIV, SPAN, THEAD, TR, TH, TBODY, URL
File "/install_dir/web2py/gluon/__init__.py", line 15, in <module>
from globals import current
File "/install_dir/web2py/gluon/globals.py", line 24, in <module>
from serializers import json, custom_json
File "/install_dir/web2py/gluon/serializers.py", line 11, in <module>
from languages import lazyT
File "/install_dir/web2py/gluon/languages.py", line 264, in <module>
PLURAL_RULES = read_possible_plurals()
File "/install_dir/web2py/gluon/languages.py", line 250, in read_possible_plurals
for pname in os.listdir(pdir):
OSError: [Errno 2] No such file or directory: '/current_dir/gluon/contrib/rules'
(不要考虑install_dir
和{
你不应该做链接。在
如果希望导入找到“gluon”,则应位于PYTHONPATH的文件夹是其父文件夹:系统路径插入(0,“/install\u dir/web2py')。在
这是可行的(这里的拉链包含胶子文件夹):
相关问题 更多 >
编程相关推荐