您好我刚刚开始试用Pyramid 1.6a我只是想创建一个多页面网站来尝试并习惯该框架。不知道我做错了什么,但我不能得到另一个页面来渲染,如0.0.0.0:1234/another-url我只能做0.0.0.0:1234/。下面是我使用pcreate -s starter,
创建的启动器__init__.py
from pyramid.config import Configurator
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('a', '/')
config.add_route('b', '/b')
config.add_route('c', '/c')
config.scan()
return config.make_wsgi_app()
views.py
from pyramid.view import view_config
from pyramid.renderers import render, render_to_response
from pyramid.response import Response
from pyramid.config import Configurator
class MyView(object):
def __init__(self, request):
self.request = request
@view_config(route_name='edit')
@view_config(route_name='change')
def edit(request):
return Response('edited!')
@view_config(route_name='a', renderer='templates/mytemplate.pt')
def a(self):
self.title = 'Oliver Test a'
return {'project': 'a'}
@view_config(route_name='b', renderer='templates/mytemplate.pt')
def b(self):
self.title = 'Oliver Test b'
return {'project': 'b'}
答案 0 :(得分:0)
您只能访问已定义的路线:
config.add_route('a', '/')
config.add_route('b', '/b')
config.add_route('c', '/c')