我正在尝试使用eve-sqlalchemy构建RESTful API。 我想使用我可以访问资源的常见模式 相应地:
127.0.0.1:5000/resource1/
127.0.0.1:5000/resource1/2
127.0.0.1:5000/resource1/2/resource2
127.0.0.1:5000/resource1/2/resource2/4
127.0.0.1:5000/resource2/
127.0.0.1:5000/resource2/4
resource1
和resource2
在父子关系中的位置。
我检查了船员的问题:How to reference an endpoint in another one?但是如果我使用&#39; url&#39; <{1}}中的配置无法使用原始resource2
和127.0.0.1:5000/resource2/4
。
如果我为127.0.0.1:5000/resource2
定义了一个额外的端点,请使用&#39; url&#39;在那里配置,然后同样的事情发生我无法以普通的方式访问resource2
。
有没有办法达到预期的效果,或者我做错了什么?
源代码:
models.py:
resource2
setting.py:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, DECIMAL, DATETIME, ForeignKey
from sqlalchemy.orm import relationship
Base = declarative_base()
class CommonColumbs(Base):
__abstract__ = True
ID = Column(Integer, primary_key=True)
CreatedAt = Column(DATETIME)
CreatedBy = Column(String)
LastModifiedAt = Column(DATETIME, nullable=True)
LastModifiedBy = Column(String)
Etag = Column(String)
class MeasurementUnitTypes(CommonColumbs):
__tablename__ = 'MeasurementUnitTypes'
Name = Column(String)
IsValid = Column(Integer)
IsSpecial = Column(Integer)
BaseUnitID = Column(Integer, ForeignKey('api.MeasurementUnits.ID'))
BaseUnit = relationship("MeasurementUnits", foreign_keys=[BaseUnitID])
__table_args__ = {"schema": "api"}
class MeasurementUnits(CommonColumbs):
__tablename__ = 'MeasurementUnits'
Name = Column(String)
ConvertValue = Column(DECIMAL(asdecimal=False))
CodeToBase = Column(String)
CodeFromBase = Column(String)
MeasurementUnitTypeID = Column(Integer, ForeignKey('api.MeasurementUnitTypes.ID'))
MeasurementUnitType = relationship("MeasurementUnitTypes", foreign_keys=[MeasurementUnitTypeID])
IsValid = Column(Integer)
__table_args__ = {"schema": "api"}