0

目录

./ksp

__init__.py
jquery.pngFix.js
manage.py
passenger_wsgi.py
settings.py
site/
site_media/
templates/
tmp/
urls.py

./ksp/网站

__init__.py
models.py
models_.py
myforms.py
urls.py
views.py
views_back.py

文件

./ksp/passenger_wsgi.py:

import os, sys
sys.path.insert(0,'/usr/lib/python2.7/site-packages/django-1.3')
sys.path.append('/home/p/pravicom/ksp/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

./ksp/urls.py:

from django.conf.urls.defaults import *
urlpatterns = patterns('',
    ('', include('site.urls')),
)

./ksp/site/urls.py:

import views
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib.auth.views import login, logout

urlpatterns = patterns('',
    (r'^$', 'views.ShowMain'),
#....
)

urlpatterns += patterns('',
    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)

./ksp/site/views.py:

from django.shortcuts import render_to_response
from models import *
from myforms import *
from django.http import HttpResponseRedirect, HttpRequest
from django import forms
from django.template import RequestContext
from django.contrib.auth.models import User
from django.contrib import auth
from django.contrib.auth.decorators import login_required
import os, urlparse, Image, sys
from django.core.paginator import Paginator, InvalidPage, EmptyPage


def custom_proc(request):
    return{
        'user': request.user
    }

def ShowMain(request):
    all_posts = Posts.objects.all().order_by('-id')

    return render_to_response("index.html", {'all_posts':all_posts}, context_instance=RequestContext(request, processors=[custom_proc]))

./ksp/settings.py:

...
ROOT_URLCONF = 'urls'
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
#    'django.contrib.sites',
#    'django.contrib.flatpages',
    'django.contrib.comments',
    'site',
)
...

结果:

异常类型:ViewDoesNotExist 异常值:
无法导入 site.views。错误是:没有名为视图的模块

4

1 回答 1

2

site将您的模块称为与 Python 的site模块发生冲突的名称很糟糕。您应该将其重命名为不会发生冲突的其他名称。您也可以通过将路径添加到sys.path

import os, sys
sys.path.insert(0,'/usr/lib/python2.7/site-packages/django-1.3')
sys.path.insert(0, '/home/p/pravicom/ksp/')

然而,这充其量是骇人听闻的,并且可能会以其他方式咬你。最好的答案是重命名你的包。

于 2013-01-25T01:58:40.360 回答