0
我似乎無法弄清楚如何使tastypie網址工作。 當我在瀏覽器中訪問我的應用程序的根目錄時,debug沒有列出url。 我錯過了什麼?django tastypie網址不起作用
## 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)),
)