1
resposta

No module named 'serializer'

Estou tendo esse erro ao importar os serializers para a página de views. OBS: estou cadastrando obras no lugar de alunos.

Traceback (most recent call last):
  File "C:\Users\ti5\Desktop\qrGimi\backendDjango\manage.py", line 19, in <module>
    main()
  File "C:\Users\ti5\Desktop\qrGimi\backendDjango\manage.py", line 15, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 393, in execute
    self.check()
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 419, in check
    all_issues = checks.run_checks(
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\ti5\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\ti5\Desktop\qrGimi\backendDjango\setup\urls.py", line 3, in <module>
    from obras.views import obras
  File "C:\Users\ti5\Desktop\qrGimi\backendDjango\obras\views.py", line 3, in <module>        
    from serializer import ObraSerializer, CursoSerializer
ModuleNotFoundError: No module named 'serializer'

CÓDIGO COMPLETO: https://github.com/lui7henrique/apiDjango

1 resposta

Eu estava tendo o mesmo problema. Resolvi colocando o nome da pasta que contem o serializer.py no import...

Com o erro, estava assim:

from serializer import ProductSerializer, ProductBarcodeSerializer, ProductAttributeSerializer

Quando resolvi, ficou assim:

from produtos.serializer import ProductSerializer, ProductBarcodeSerializer, ProductAttributeSerializer