Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试django tastypie时遇到的问题_Django_Tastypie - Fatal编程技术网

测试django tastypie时遇到的问题

测试django tastypie时遇到的问题,django,tastypie,Django,Tastypie,我在这里举一个例子: My URL.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() urlp

我在这里举一个例子: My URL.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')
我得到的错误是:

at/api/tours配置不当

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

实体资源从何处获取其URL?它不在示例中?

您使用类EntryResource而不是该类的实例entry\u resource

(r'^api/', include(EntryResource.urls)),
更改它:

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

天哪,你是对的!我现在有一个新的错误,但谢谢你在这两天里一直在研究。。。先生,你是一位真正的绅士!你使用代码检查器吗?我使用flake8,它会在类似这样的情况下通知我(例如,变量未使用)。