目录
./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。错误是:没有名为视图的模块