ModuleNotFoundError:没有名为' api.serializers'

时间:2017-02-03 07:02:38

标签: python django django-models django-views django-rest-framework

我安装了Django 1.10和Django REST框架。

我正在尝试执行serealization但是我收到以下错误:

python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f3a65e76840>
Traceback (most recent call last):
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/urls/resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/user/projects/django/webserv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/home/user/projects/django/cfdi/cfdi/urls.py", line 22, in <module>
    url(r'^api/', include('api.urls')),
  File "/home/user/projects/django/webserv/lib/python3.6/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/home/user/projects/django/webserv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/home/user/projects/django/cfdi/api/urls.py", line 4, in <module>
    from . import views
  File "/home/user/projects/django/cfdi/api/views.py", line 11, in <module>
    from .serializers import ReportSerializer, InvoiceSerializer, UserProfileSerializer
ModuleNotFoundError: No module named 'api.serializers'

这是我的serializer.py的内容:

from rest_framework import serializers
from cfdipanel.models import Report, Invoice, UserProfile

class UserProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserProfile
        fields = ('user', 'karma')


class InvoiceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Invoice
        fields = ('uuid', 'owner')


class ReportSerializer(serializers.ModelSerializer):
    owner = UserProfileSerializer(read_only=True)
    ownerId = serializers.PrimaryKeyRelatedField(write_only=True,
                                                 queryset=UserProfile.objects.all(),
                                                 source='owner')
    invoices = InvoiceSerializer(many=True,
                                 read_only=True,
                                 source='invoice_set')

    class Meta:
        model = Report
        fields = ('id', 'title', 'body', 'owner', 'ownerId', 'invoices')

是一个包含2个应用程序api和cfdipanel的项目,有人可以指导我吗?

0 个答案:

没有答案