2011-04-22 6 views
4

그래서 Django 용 TastyPie 플러그인을 사용하여 프로젝트에 REST API를 만들기 시작했습니다. 프로젝트 시작 가이드를 따르고 있었지만, this point에 들어갔을 때 외래 키를 입력해야했을 때 오류가 발생했습니다. 나는 간단한 GET을 수행 할 때외래 키

maior 하나는 이것이다 :

"Reverse for 'api_dispatch_detail' with arguments '()' and keyword arguments '{'pk': 246, 'api_name': 'v1', 'resource_name': 'typep'}' not found." 

resources.py의 코드 :

class TypeOfPlaceResource(ModelResource): 

    class Meta: 
     queryset = TypeOfPlace.objects.all() 
     resource_name = 'typep' 
     allowed_methods = ['get'] 

class POIResource(ModelResource): 

    typep = ForeignKey(TypeOfPlaceResource, 'typep') 

    class Meta: 
     queryset = PointOfInterest.objects.all() 
     resource_name = 'pois' 
     filtering = { 
      "code1": ALL, 
      "code2": ALL, 
     } 

그리고 모델 :

class TypeOfPlace (models.Model): 
    name = models.CharField(max_length=100, blank=True) 
    code = models.CharField(max_length=20, unique=True) 

    def __unicode__(self): 
     return self.name 

class PointOfInterest(GeoInformation): 
    name = models.CharField(max_length=100,blank=True) 
    code1 = models.CharField(max_length=4,null=True, unique=True) 
    code2 = models.CharField(max_length=4,null=True, unique=True) 
    typep = models.ForeignKey(TypeOfPlace) 

    def __unicode__(self): 
     return self.name 

urls.py

api = Api(api_name='v1') 
api.register(TypeOfPlaceResource(), canonical=True) 
api.register(POIResource(), canonical=True) 

urlpatterns = api.urls 

그래서 내가 잘못하고 있니? 아니면 뭔가 빠졌습니까? 어떤 도움이라도 정말 감사 할 것입니다! : D

+1

TastyPie URLconf를 추가 할 수 있습니까? – manji

+0

예! 그냥 주요 질문을 편집] : –

+2

당신이 무슨 URL을 입력 했 습니까이 문제가 발생 했습니까? 'urlpatterns = patterns ('', (r '^ api /', include (api.urls)))로 변경하십시오. – manji

답변

3

내 문제에 대한 최종 답변은 @manji에서 대답하고 @dlrust 결합 의지".

다른 사람들에게 유용 할 것입니다. :)

1

urlpatterns이 덮어 쓰기가 가능한 것 같습니다.

urlpatterns += api.urls; 

이 작품과 같이 +=을 추가합니까? urlpatterns에 직접 할당하면 예전에받은 과제가 예기치 않게 걸릴 수 있습니다.

"urlpatterns = patterns('', (r'^api/', include(api.urls)),)urlpatterns 값을 변경"과, 그 이후 "를위한 당신의 메타에 권한을 정의