Django ImportError在/无论我做什么

Ste*_*uso 3 python django

所以我刚开始玩Django,我决定尝试一下我的服务器.所以我按照Djangoproject.com教程中概述的基础知识安装了Django并创建了一个新项目

不幸的是,无论我做什么,我都无法获得工作的意见:我经常得到

ImportError at /

No module named index
Run Code Online (Sandbox Code Playgroud)

以下是此错误的屏幕截图

我一直在谷歌搜索和尝试各种命令,没有运气,我真的要撕掉我的头发,直到我变成秃头.我已经尝试将django源目录,我的项目目录和app目录添加到PYTHONPATH而没有运气.我还确保init .py在所有目录中(包括项目和应用程序)有没有人知道这里可能出现什么问题?

更新

对不起,我发布这篇文章的时候很匆忙,这里有一些背景信息:

我一直在尝试的服务器只是django的内置服务器使用manage.py(python manage.py 0.0.0.0:8000,因为我需要在外部访问它)在linux上(debian)

APPDIR/views.py

from django.http import HttpResponse

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

def test(request):
    return HttpRespons("heyo")
Run Code Online (Sandbox Code Playgroud)

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'))
)
Run Code Online (Sandbox Code Playgroud)

S.L*_*ott 12

urls.py错了; 你应该考虑阅读这个这个.

你没有包含一个功能; 你包括一个模块.你命名一个函数,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')
)
Run Code Online (Sandbox Code Playgroud)

  • 我爱你.就像,严肃地说,我非常爱你.随意拥有我的宝宝. (5认同)