Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python上否定match_param?(金字塔)_Python_Pyramid - Fatal编程技术网

如何在python上否定match_param?(金字塔)

如何在python上否定match_param?(金字塔),python,pyramid,Python,Pyramid,我希望能够加载(localhost:6543/users) 它不加载,因为它需要第二个参数(例如localhost:6543/users/x) 我意识到这个问题,因为我把它设置在我的路线上 config.add_route('users', '/users/{action}') 这是我的init.py def includeme(config): config.add_static_view('user_static', 'user:static', cache_max_age=3

我希望能够加载(localhost:6543/users)

它不加载,因为它需要第二个参数(例如localhost:6543/users/x)

我意识到这个问题,因为我把它设置在我的路线上

config.add_route('users', '/users/{action}')
这是我的init.py

def includeme(config):
    config.add_static_view('user_static', 'user:static', cache_max_age=3600)
    config.add_static_view('static', 'user:static', cache_max_age=3600)
    config.add_route('users', '/users/{action}')
    config.scan()
这是我的观点

class UserView:

def __init__(self, request):
    self.request = request

@view_config(route_name='users', renderer='templates/users.jinja2')
def users(self):
    return {'title': 'Users'}


@view_config(route_name='users', renderer='json', match_param='action=list')
def list(self):
    #return list   

@view_config(route_name='users', renderer='json', match_param='action=add')
def add(self):
    #add new user

@view_config(route_name='users', renderer='json', match_param='action=getUser')
def getUser(self):
   #retrieve data for update

@view_config(route_name='users', renderer='json', match_param='action=updateUser')
def updateUser(self):
    #update record

感谢您的回答,如果您能对我的代码进行一些改进,请告诉我。

我想我应该使用另一种方法来完成我的所有操作

def includeme(config):
    config.add_static_view('user_static', 'user:static', cache_max_age=3600)
    config.add_static_view('static', 'user:static', cache_max_age=3600)
    config.add_route('users', '/users')
    config.add_route('action', '/action/{action}')
    config.scan()
并修改视图,将用户更改为操作

class UserView:

def __init__(self, request):
    self.request = request

@view_config(route_name='users', renderer='templates/users.jinja2')
def users(self):
    return {'title': 'Users'}


@view_config(route_name='action', renderer='json', match_param='action=list')
def list(self):
    #return list   

@view_config(route_name='action', renderer='json', match_param='action=add')
def add(self):
    #add new user

@view_config(route_name='action', renderer='json', match_param='action=getUser')
def getUser(self):
    #retrieve data for update

@view_config(route_name='action', renderer='json', match_param='action=updateUser')
def updateUser(self):
    #update record

您必须在此处定义两条管线,这是正确的。一个有图案,一个没有。这不是严格必要的,但它是最好的方法。您可以使用
/users/{action}
或其他模式来命名第二个
user\u action