Erik Barajas
Erik Barajas

Reputation: 193

ImportError: No module named app.views django 1.10 python

I just have started learning django in its 1.10 version. In a project (called refugio) I have created an app called mascota.

This is my views.py file for my app:

from __future__ import unicode_literals, absolute_import
from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse("Index")

Also, I already have written my urls.py file for it:

from django.conf.urls import url
from apps.mascota.views import index

urlpatterns = [
    url(r'^$/', index),
]

And I have modified the url.py file of my project:

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('apps.mascota.urls')),
]

But when I run the server of my project, it sends me the next error message: enter image description here

If it helps, My dir tree is the following:

REFUGIO apps mascota views.py urls.py refugio settings.py urls.py manage.py

I know this is a dummy question, but I don't know what is wrong, I have already checked my urls sentences, but I see everything ok.

I will appreciate your help.

Ps.: My app is located inside a folder called apps.

Regards.

Upvotes: 0

Views: 980

Answers (2)

Tomasz Jakub Rup
Tomasz Jakub Rup

Reputation: 10680

Every Python package need __init__.py file (read this).

REFUGIO
    apps
        mascota
            __init__.py
            views.py
            urls.py
        __init__.py
    refugio
        __init__.py
        settings.py
        urls.py
    manage.py

Upvotes: 0

Peter Chow
Peter Chow

Reputation: 41

Change your file structure into

REFUGIO
    mascota
        views.py
        urls.py
    refugio
        settings.py
        urls.py
    manage.py

and then change the line in urls.py

from apps.mascota.views import index

into

form mascota.views import index

Hope this helps.

Upvotes: 0

Related Questions