Django tastypie资源导入错误

时间:2014-03-07 16:31:26

标签: python django python-2.7 django-models tastypie

运行我的django应用程序时出现此错误。

    Internal Server Error: /
Traceback (most recent call last):
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/handlers/base.py", line 101, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/urlresolvers.py", line 318, in resolve
    for pattern in self.url_patterns:
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/urlresolvers.py", line 346, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/core/urlresolvers.py", line 341, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/DjangoBlog/DjangoBlog/urls.py", line 7, in <module>
    url(r'^articles/', include('article.urls')),
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 26, in include
    urlconf_module = import_module(urlconf_module)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/DjangoBlog/article/urls.py", line 3, in <module>
    from api import ArticleResource
  File "/Users/amritdeepdhungana/Project/DjangoApp/DENV/DjangoBlog/article/api.py", line 3, in <module>
    from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
ImportError: No module named tastypie.resources
[07/Mar/2014 10:21:20] "GET / HTTP/1.1" 500 111837

urls.py文件

    from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^articles/', include('article.urls')),
    # Examples:
    # url(r'^$', 'DjangoBlog.views.home', name='home'),
    # url(r'^DjangoBlog/', include('DjangoBlog.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),

    # User registration
    url(r'^accounts/login/$', 'DjangoBlog.views.login'),
    url(r'^accounts/auth/$', 'DjangoBlog.views.auth_view'),
    url(r'^accounts/logout/$', 'DjangoBlog.views.logout'),
    url(r'^accounts/loggedin$', 'DjangoBlog.views.loggedin'),
    url(r'^accounts/invalid/$', 'DjangoBlog.views.invalid_login'),
    url(r'^accounts/register/$', 'DjangoBlog.views.register_user'),
    url(r'^accounts/register_success/$', 'DjangoBlog.views.register_success'),  
)

文章urls.py文件是

    from django.conf.urls import patterns, include, url
from api import ArticleResource

article_resource = ArticleResource()

urlpatterns = patterns('',
    url(r'^all/$', 'article.views.articles'),
    url(r'^get/(?P<article_id>\d+)/$', 'article.views.article'),
    url(r'^language/(?P<language>[a-z\-]+)/$', 'article.views.language'),
    url(r'^create/$', 'article.views.create'),
    url(r'^like/(?P<article_id>\d+)/$', 'article.views.like_article'),
    url(r'^add_comment/(?P<article_id>\d+)/$', 'article.views.add_comment'),
    url(r'^search/$', 'article.views.search_titles'),
    url(r'^api/', include(article_resource.urls)),
)

The article api.py file

# from tastypie.resources import ModelResource
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from tastypie.constants import ALL
from models import Article

class ArticleResource(ModelResource):
    class Meta:
        queryset = Article.objects.all()
        resource_name = 'article'
        filtering = { "title" : ALL }

tastypie资源导入正确,但我的应用程序仍未运行。在我的机器上,我安装了这个点子

pip freeze
Django==1.5.5
django-tastypie==0.11.0
mimeparse==0.1.3
python-dateutil==2.2
python-mimeparse==0.1.4
six==1.5.2
vboxapi==1.0
virtualenv==1.10.1
wsgiref==0.1.2

0 个答案:

没有答案