Django休息框架导入错误在django.test.client

时间:2017-02-27 10:31:51

标签: python django google-app-engine django-rest-framework importerror

我正在使用谷歌应用引擎开发服务器在mac os上运行python。 我正在运行的项目是一个使用djangae和django休息框架的appengine django项目。

项目中的所有内容都可以正常工作,但是一旦声明与rest_framework相关的导入,我就会收到关于django.test.client的错误,尽管我目前没有运行任何测试。

我尝试执行的导入是“来自rest_framework.decoraters import api_view”,只要我进行此导入或与其余框架相关的任何其他导入。

这是我所做的每个导入所涉及的其余框架的错误。

ERROR    2017-02-27 10:19:08,019 base.py:256] Internal Server Error: /_ah/warmup
Traceback (most recent call last):
File "/Users/MyUser/git/project-name/src/lib/django/core/handlers/base.py", line 223, in get_response
    response = middleware_method(request, response)
File "/Users/MyUser/git/project-name/src/core/middleware/url_definition.py", line 32, in process_response
    response = redirect('%s/' % request.path)
File "/Users/MyUser/git/project-name/src/lib/django/shortcuts.py", line 116, in redirect
    return redirect_class(resolve_url(to, *args, **kwargs))
File "/Users/MyUser/git/project-name/src/lib/django/shortcuts.py", line 205, in resolve_url
    return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "/Users/MyUser/git/project-name/src/lib/django/core/urlresolvers.py", line 578, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/Users/MyUser/git/project-name/src/lib/django/core/urlresolvers.py", line 432, in _reverse_with_prefix
    self._populate()
File "/Users/MyUser/git/project-name/src/lib/django/core/urlresolvers.py", line 284, in _populate
    for pattern in reversed(self.url_patterns):
File "/Users/MyUser/git/project-name/src/lib/django/core/urlresolvers.py", line 401, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/MyUser/git/project-name/src/lib/django/core/urlresolvers.py", line 395, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/core/urls.py", line 34, in <module>
    url(r'^', include('pages.urls'), name='pages.urls')
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/urls.py", line 31, in <module>
    url(r'^myapp/', include('pages.myapp.urls', namespace='rest_framework'), name="pages.myapp"),
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/myapp/urls.py", line 4, in <module>
    url(r'^finance/', include('pages.myapp.finance.urls'), name='pages.myapp.finance'),
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/myapp/finance/urls.py", line 4, in <module>
    url(r'^api/', include('pages.myapp.finance.api.urls'), name='pages.myapp.finance.api.urls'),
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/myapp/finance/api/urls.py", line 4, in <module>
    url(r'^service/', include('pages.myapp.finance.api.service.urls'), name='pages.myapp.finance.api.service'),
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/myapp/finance/api/service/urls.py", line 8, in <module>
    url(r'^user/', include('pages.myapp.finance.api.service.user.urls'),
File "/Users/MyUser/git/project-name/src/lib/django/conf/urls/__init__.py", line 33, in include
    urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/MyUser/git/project-name/src/pages/myapp/finance/api/service/user/urls.py", line 3, in <module>
    from pages.myapp.finance.api.service.user import functions
File "/Users/MyUser/git/project-name/src/pages/myapp/finance/api/service/user/functions.py", line 5, in <module>
    from rest_framework.decorators import api_view
File "/Users/MyUser/git/project-name/src/lib/rest_framework/decorators.py", line 15, in <module>
    from rest_framework.views import APIView
File "/Users/MyUser/git/project-name/src/lib/rest_framework/views.py", line 19, in <module>
    from rest_framework.request import Request
File "/Users/MyUser/git/project-name/src/lib/rest_framework/request.py", line 23, in <module>
    from rest_framework.settings import api_settings
File "/Users/MyUser/git/project-name/src/lib/rest_framework/settings.py", line 24, in <module>
    from django.test.signals import setting_changed
File "/Users/MyUser/git/project-name/src/lib/django/test/__init__.py", line 5, in <module>
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 999, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named django.test.client

1 个答案:

答案 0 :(得分:2)

如果您在应用引擎上遇到此类导入错误,请务必检查app.yaml中的skip_files

例如:

skip_files:
  - ^(.*/)?.*/test/.*$

制作&#39; django / test&#39;文件夹在您的开发环境中无法导入,并且该文件夹不会部署到应用引擎。