gpt4 book ai didi

python - 将 tastypie 导入到项目中

转载 作者:太空宇宙 更新时间:2023-11-03 18:25:32 25 4
gpt4 key购买 nike

我正在学习如何使用 tastypie 并使用命令 sudo pip install django-tastypie 安装它。

我想尝试一下:

from tastypie.resources import ModelResource
from tastypie.resources import ALL
from models import Article

但是我得到:

Traceback:
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/handlers/base.py" in get_response
101. resolver_match = resolver.resolve(request.path_info)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in resolve
318. for pattern in self.url_patterns:
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in url_patterns
346. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/core/urlresolvers.py" in urlconf_module
341. self._urlconf_module = import_module(self.urlconf_name)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/utils/importlib.py" in import_module
40. __import__(name)
File "/Users/username/Development/django_tutorial/bin/django_test/django_test/urls.py" in <module>
14. (r'^articles/', include('article.urls')), # links to article/urls
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/conf/urls/__init__.py" in include
26. urlconf_module = import_module(urlconf_module)
File "/Users/username/Development/django_tutorial/lib/python2.7/site-packages/Django-1.6.2-py2.7.egg/django/utils/importlib.py" in import_module
40. __import__(name)
File "/Users/username/Development/django_tutorial/bin/django_test/article/urls.py" in <module>
4. from api import ArticleResource
File "/Users/username/Development/django_tutorial/bin/django_test/article/api.py" in <module>
1. from tastypie.resources import ModelResource

Exception Type: ImportError at /articles/api/article/
Exception Value: No module named tastypie.resources

最佳答案

您可能会忘记两件事:

1) 将 tastypie 添加到 setting.py 中已安装的应用中

INSTALLED_APPS = (
.....
'tastypie',


)

或者2) 你可能在env之外安装了tastypie ..

关于python - 将 tastypie 导入到项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23285808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com