Django tastypie resources Import Error

天涯浪子 提交于 2019-12-13 02:25:49

问题


I am getting this error while running my django application.

    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

The urls.py file

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

The article urls.py file is

    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 resources is import properly but still my application is not running. And in my machine, I have install this pip

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

来源:https://stackoverflow.com/questions/22255537/django-tastypie-resources-import-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!