0

我在这里遵循示例:http: //django-tastypie.readthedocs.org/en/latest/tutorial.html 我的 urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin

from django.conf.urls.defaults import *
from ristoturisto.api import EntryResource

entry_resource = EntryResource()
admin.autodiscover()
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    (r'^blog/', include('ristoturisto.urls')), #this basically points to it self?
    (r'^api/', include(EntryResource.urls)),

)

api.py

from tastypie.resources import ModelResource
from locations.models import tours


class EntryResource(ModelResource):
    class Meta:
        queryset = tours.objects.all()
        resource_name = 'Tours'

楷模:

class tours(models.Model):
    name = models.CharField(max_length=255)
    categories = models.ForeignKey('categories')
    icon = models.CharField(max_length=255)
    publishdate = models.CharField(max_length=255)
    locations = models.ManyToManyField('geolocations')

我得到的错误是:

/api/tours 配置不当

当我尝试访问时:http://127.0.0.1:8000/api/tours?format=json

Entity_resource 从哪里得到它的 URL?例子里没有吗?

4

1 回答 1

1

您使用类EntryResource而不是此类entry_resource的实例:

(r'^api/', include(EntryResource.urls)),

更改:

(r'^api/', include(entry_resource.urls)),
于 2013-06-20T06:31:14.183 回答