0

Tastypie の URL を機能させる方法がわかりません。ブラウザでアプリケーションのルートに移動すると、デバッグで URL が一覧表示されません。何が欠けていますか?

## inventory/models.py
from django.db import models
#
class Server (models.Model):
    server_id  = models.AutoField(primary_key=True)
    server_name = models.CharField("Server Name",max_length=200,unique=True)
    server_ip = models.IPAddressField("Server IP")
    server_serial = models.CharField("Serial No.",max_length=25,null=True,blank=True)
    server_mem = models.PositiveIntegerField("Mem (MB)",null=True,blank=True)
    server_architecture = models.ForeignKey(Architecture)
    server_os = models.ForeignKey(Operating_System)
    server_os_version = models.CharField("OS   Version",max_length="25",null=True,blank=True)
    server_type = models.ForeignKey(Server_Type,null=True,blank=True)
    server_mac = models.ForeignKey(Mac,null=True,blank=True)
    server_digi = models.ForeignKey(Digi,null=True,blank=True)
    server_digi_port = models.PositiveIntegerField("Digi Port",null=True,blank=True)
    server_rack = models.ForeignKey(Rack,null=True,blank=True)
    server_kvm = models.ForeignKey(KVM,null=True,blank=True)
    def __unicode__(self):
            return self.server_name

## inventory/api.py
from tastypie.resources import ModelResource
from inventory.models import *
#
class ServerResource(ModelResource):
 class Meta:
    queryset = Server.objects.all()
    resource_name = 'servers'

## mmi_assets/urls.py
from django.conf.urls import patterns, include, url
#
## our custom stuff
from inventory.api import *
server_resource = ServerResource()
##

urlpatterns = patterns('',
  url(r'^admin/', include(admin.site.urls)),
  url(r'^inventory/', include('inventory.urls')),
  url(r'^api/', include(server_resource.urls)),
)
4

1 に答える 1

1

リソースを API に追加してから、API の URL を含める必要があります。http://django-tastypie.readthedocs.org/en/latest/tutorial.html#adding-to-the-api

# urls.py
from django.conf.urls.defaults import *
from tastypie.api import Api
from myapp.api import EntryResource, UserResource

v1_api = Api(api_name='v1')
v1_api.register(UserResource())
v1_api.register(EntryResource())

urlpatterns = patterns('',
    # The normal jazz here...
    (r'^blog/', include('myapp.urls')),
    (r'^api/', include(v1_api.urls)),
)
于 2013-03-29T19:01:11.623 に答える