Steve Gattuso Steve Gattuso - 2 months ago 7
Python Question

Django ImportError at / no matter what I do

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

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

ImportError at /

No module named index


Here is a screenshot of this error

I've been googling and trying various commands with no luck, and I'm literally about to tear my hair out until I become bald. I've tried adding the django source directory, my project directory, and the app directory to PYTHONPATH with no luck. I've also made sure that init.py is in all of the directories (both project and app) Does anyone have any idea as to what could be going wrong here?

UPDATES

Sorry, I was in kind of a rush while posting this, here's some context:

The server I've been trying is just django's built in server using manage.py (python manage.py 0.0.0.0:8000, since I need to access it externally) 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'))
)

Answer

Your urls.py is wrong; you should consider reading this and this.

You don't include a function; you include a module. You name a function, mecore.views.index. You only include entire modules 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')
)