0
我想創建一個Django網站,更重要的是,導入TastyPie API。但每次我在我的本地運行/用品/ API /條,我得到這個錯誤信息:試圖導入TastyPie API,但我沒有找到頁面消息
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/articles/api/article
Using the URLconf defined in django_test.urls, Django tried these URL patterns, in this order:
1. ^admin/
2. ^accounts/login/$
3. ^accounts/auth/$
4. ^accounts/loggedin/$
5. ^accounts/invalid/$
6. ^accounts/logout/$
7. ^accounts/register/$
8. ^accounts/register_success/$
9. ^articles/all/$
10. ^articles/create/$
11. ^articles/get/(?P<article_id>\d+)/$
12. ^articles/like/(?P<article_id>\d+)/$
13. ^articles/add_comment/(?P<article_id>\d+)/$
14. ^articles/search/
15. ^articles/api/article ^(?P<resource_name>article)/$ [name='api_dispatch_list']
16. ^articles/api/article ^(?P<resource_name>article)/schema/$ [name='api_get_schema']
17. ^articles/api/article ^(?P<resource_name>article)/set/(?P<pk_list>.*?)/$ [name='api_get_multiple']
18. ^articles/api/article ^(?P<resource_name>article)/(?P<pk>.*?)/$ [name='api_dispatch_detail']
The current URL, articles/api/article, didn't match any of these.
這裏是我的urls.py文件,它位於我django_test/django_test目錄下:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django_test.api import ArticleResource
article_resource = ArticleResource()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/login/$', 'django_test.views.login'),
url(r'^accounts/auth/$', 'django_test.views.auth_view'),
url(r'^accounts/loggedin/$', 'django_test.views.loggedin'),
url(r'^accounts/invalid/$', 'django_test.views.invalid_login'),
url(r'^accounts/logout/$', 'django_test.views.logout'),
url(r'^accounts/register/$', 'django_test.views.register_user'),
url(r'^accounts/register_success/$', 'django_test.views.register_success'),
url(r'^articles/all/$', 'article.views.articles'),
url(r'^articles/create/$', 'article.views.create'),
url(r'^articles/get/(?P<article_id>\d+)/$', 'article.views.article'),
url(r'^articles/like/(?P<article_id>\d+)/$', 'article.views.like_article'),
url(r'^articles/add_comment/(?P<article_id>\d+)/$', 'article.views.add_comment'),
url(r'^articles/search/', 'article.views.search_titles'),
url(r'^articles/api/article', include(article_resource.urls)),
)
,這是我api.py文件,它也位於我django_test/django_test目錄:
from tastypie.resources import ModelResource
from tastypie.constants import ALL
from article.models import Article
class ArticleResource(ModelResource):
class Meta:
queryset = Article.objects.all()
resource_name = 'article'
我想,說不同的錯誤信息:
「對不起,尚未實現。請追加「格式= JSON?」你的URL「
我真的很困惑,我將不勝感激任何幫助,您可以給我謝謝
看起來你需要傳遞一個RESOURCE_NAME參數,如:。 http://127.0.0.1:8000/articles/api/article/myresource – Selcuk 2015-02-10 16:51:54
我正在看TastyPie文檔,但我不知道'resource_name'是什麼意思。你的意思是把'resource_name'放在urls.py中? – brown1001 2015-02-10 16:55:53