2013-06-20 72 views
0

我在這裏繼例如:http://django-tastypie.readthedocs.org/en/latest/tutorial.html 我的urls.py:問題測試的Django tastypie

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') 

我得到的錯誤是:

ImproperlyConfigured在/ API /旅遊

當我試圖訪問:http://127.0.0.1:8000/api/tours?format=json

哪裏Entity_resource得到它的URL從公司?這不是在這個例子中?

回答

1

您可以使用類而不是這個類entry_resource實例EntryResource

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

改變它:

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

老天爺你是對的!我現在有一個新的錯誤,但是,謝謝你,爲期兩天......你的先生是一個真正的紳士! – R0b0tn1k

+1

你使用任何代碼檢查器?我使用flake8,並在這種情況下通知我(例如,變量未使用)。 https://pypi.python.org/pypi/flake8 –