Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
ModuleNotFoundError: No module named 'PyDemo.accounts'

I am working on a Django app that will host a simple index.html file:

url.py:

from django.conf.urls import url,include
from django.contrib import admin
from PyDemo.accounts.views import my_view 

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^demo/',my_view)
]

views.py:

from django.shortcuts import render_to_response
from django.template import RequestContext

# Create your views here.

def my_view(request):
    return render_to_response('index.html',locals(),context_instance=RequestContext(request))

However, when I run the app, I get the following error:

    return import_module(self.urlconf_name)
  File "C:\Users\tcssuoy\Desktop\DJANGO\mysite\lib\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 "C:\Users\tcssuoy\workspace\PyDemo\PyDemo\PyDemo\urls.py", line 18, in <module>
    from PyDemo.accounts.views import my_view 
ModuleNotFoundError: No module named 'PyDemo.accounts'
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It seems like your project name is PyDemo and the name of the module is accounts. So try using

from accounts.views import my_view

You may find an error (underlined by red mark) that is because of your IDE so ignore it and migrate it. It will work

about 4 years ago · Santiago Trujillo Relatório

0

For anyone else with this issue who is migrating from Python 2 to 3 it seems to be because Python 3 is more discerning about where to find modules. @Ranjith Singhu's comment sent me in the right direction. In my case I had to change:

Python 2:

from views import MyView

Python 3 (also fine in 2):

from project_name.views import MyView
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda