django_rest.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:apimas 作者: grnet 项目源码 文件源码
def construct_endpoint(self, instance, spec, loc, context):
        """
        Constructor of '.endpoint' predicate.

        It gets the generated views and it maps them with urlpatterns which
        will later be used from django.
        """
        parent_name = context.get('parent_name')
        collections = self.get_structural_elements(instance)
        if not collections:
            raise utils.DRFAdapterException(
                '.endpoint without any collection found.', loc=loc)
        router = routers.DefaultRouter()
        for collection in collections:
            collection_spec = instance.get(collection)
            view = collection_spec.get(self.ADAPTER_CONF)
            basename = parent_name + '_' + collection
            router.register(collection, view, base_name=basename)
        self.urls[parent_name] = url(
            r'^' + parent_name + '/', include(router.urls))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号