Django ImportError at / no matter what I do

So, I just started playing with Django, and I decided to try it on my server. So I installed Django and created a new project, following the basics outlined in the Djangoproject.com tutorial

Unfortunately, no matter what I do, I can't get the views to work: I constantly get

ImportError at /

No module named index

Here is a screenshot of this error

I searched Google and tried to execute different commands without any luck, and I'm literally going to rip my hair out until I become bald. I tried adding the django source directory, my project directory and application directory to PYTHONPATH with no luck. I also made sure init .py is in all directories (both in the project and in the application). Does anyone have an idea what might be wrong here?

UPDATES

Sorry, I was in a hurry posting this, here is some context:

The server I tried was only django built into the server using manage.py (python manage.py 0.0.0.0:8000, since I need to access it from the outside) on linux (debian)

AppDir / views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Sup")

def test(request):
    return HttpRespons("heyo")

urls.py

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^****/', include('****.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
    (r'^test/', include('mecore.views.test')),
    (r'^', include('mecore.views.index'))
)
+3
source share
3

urls.py ; this.

; . mecore.views.index. include('mecore.views').

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Example:
    # (r'^****/', include('****.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
    (r'^test/', 'mecore.views.test'),
    (r'^', 'mecore.views.index')
)
+12

__init__.py mecore views, index.py ?

Python, __init__.py ( , - , ).

: , include python , : . Django - , , , include, @S.Lott .

+3

From ImportError No module named :

Try and move views.pyto mysite internal directory. Views are part of the application, so you need to move them to the application directory (and not to the project directory).

The error message received indicates that mysite(the application) does not have a module views.py.

-1
source

Source: https://habr.com/ru/post/1710529/


All Articles