tags:

views:

198

answers:

2

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'))
)
+6  A: 

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')
)
S.Lott
I just added a few source files and some information, I think that should help us find the problem.
Vestonian
I love you. Like, seriously, I love you so much. Feel free to have my babies.
Vestonian
+2  A: 

Do you have __init__.py in each of the mecore and views directories, as well as an index.py in views?

A directory is a package, from Python's viewpoint, only if it has a file named __init__.py (it may be empty, if you don't need to execute any special code when that package is imported, but it has to be there).

Edit: note that in include you must name the python path to a module, not to a function: see Django's relevant docs -- judging from your comment you appear to be mis-using include, as I see @S.Lott had surmised in his answer.

Alex Martelli
There is no mecore/views/ directory. There's only /mecore/ and views.py is a file in /mecore/ with all of the functions in it, as described in the Django tutorial (Part 3 I believe)
Vestonian
Hmmm, not with include() surely? include() must contain the Python path to a module, not to a function.
Alex Martelli