问题描述
我从快速教程页面here创建了一个简单的Pyramid应用程序,其中包含与问题相关的以下文件:
-
private void DgvGrd_SizeChanged(object sender,EventArgs e) { dgvGrd.Columns[0].Width = (int)(dgvGrd.Width * 0.2); dgvGrd.Columns[1].Width = (int)(dgvGrd.Width * 0.2); dgvGrd.Columns[2].Width = (int)(dgvGrd.Width * 0.4); dgvGrd.Columns[3].Width = (int)(dgvGrd.Width * 0.2); // also may be a good idea to set FILL for the last column // to accomodate the round up in conversions dgvGrd.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; }
:
tutorial/__init__.py
-
from pyramid.config import Configurator def main(global_config,**settings): config = Configurator(settings=settings) config.include('pyramid_chameleon') config.add_route('home','/') config.add_route('hello','/howdy') config.add_static_view(name='static',path='tutorial:static') config.add_route('image','/{filename}') config.scan('.views') return config.make_wsgi_app()
:
tutorial/views/views.py
-
from pyramid.view import ( view_config,view_defaults ) @view_defaults(renderer='../templates/home.pt') class TutorialViews: def __init__(self,request): self.request = request @view_config(route_name='home') def home(self): return {'name': 'Home View'} @view_config(route_name='hello') def hello(self): return {'name': 'Hello View'} @view_config(route_name='image',renderer='../templates/image.pt') def image(request): filename = request.matchdict.get('filename') return {'name': 'Hello View','filename': filename}
:
tutorial/templates/image.pt
我已将图像文件放置在路径<!DOCTYPE html>
<html lang="en">
<head>
<title>Quick Tutorial: ${name}</title>
<link rel="stylesheet"
href="${request.static_url('tutorial:static/app.css') }"/>
</head>
<body>
<h1>Hi ${name}</h1>
<img src="../static/images/${filename}">
</body>
</html>
上。现在,这是我尝试过的3种情况以及使用tutorial/static/images/test.jpeg
启动服务器时的结果:
-
pserve development.ini --reload
中的路由配置:tutorial/__init__.py
。当我访问config.add_route('image','/{filename}')
时,可以看到该图像,并且一切正常。 -
localhost:6543/test.jpeg
中的路由配置:tutorial/__init__.py
。当我访问config.add_route('image','/foo/{filename}')
时,可以看到该图像,并且一切正常。 -
localhost:6543/foo/test.jpeg
中的路由配置:tutorial/__init__.py
。当我访问config.add_route('image','/foo/bar/{filename}')
时,这是我 不 看到图像的时候。
在上述情况3)中,我尝试了一些操作,并且只有在文件localhost:6543/foo/bar/test.jpeg
中将行tutorial/templates/image.pt
更改为<img src="../static/images/${filename}">
时,才能看到图像。我似乎无法理解为什么Pyramid强迫我在模板中添加另一个目录层以查看图像。谁能解释为什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)