简体   繁体   中英

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: 在此处输入图片说明

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM