当我访问项目的 url“localhost:8000/adminPonto”(我是巴西人)时,我的 Django 项目中出现TypeError 'str' object is not callable 。它遵循urls.py(错误所在)和adminApp.views(与 urls.py 相关的代码,因此与错误相关的代码)的代码:
网址.py
# -- coding:iso-8859-1 --
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
import baterPonto.views
import adminApp.views
import PontoCOSGEM.views
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Sistema de Ponto
(r'^ponto/$',baterPonto.views.index), # Pagina inicial da administracao do registro de ponto
(r'^ponto/registrar/$',baterPonto.views.registrar_ponto),
# Administracao do Ponto
(r'^adminPonto/$',adminApp.views.loginIndex), # Formulario de login da admin. de ponto
(r'^adminPonto/login/$',adminApp.views.entrar), # Pagina de login da admin. de ponto
(r'^adminPonto/logout/$',adminApp.views.sair), # Pagina de logout da admin. de ponto
(r'^adminPonto/index/$',adminApp.views.index), # Pagina inicial do sistema de adm.
# Gerencia de Funcionarios
(r'^adminPonto/funcionarios/$',adminApp.views.funcionariosIndex), # Menu de gerência dos funcionarios
'''(r'^adminPonto/funcionarios/search/$',adminApp.views.funcionariosSearch), # Procura por funcionario
(r'^adminPonto/funcionarios/add/$',adminApp.views.funcionariosAdd), # Adiciona funcionarios
(r'^adminPonto/funcionarios/edit/$',adminApp.views.funcionariosEdit), # Edita funcionarios
(r'^adminPonto/funcionarios/delete/$',adminApp.views.funcionariosDelete), # Apaga funcionarios
(r'^adminPonto/funcionarios/list/$',adminApp.views.funcionariosList), # Lista todos os funcionarios'''
# Relatorio de Ponto
(r'^adminPonto/relatorios/$',adminApp.views.relatorioIndex), # Menu de relatorio de ponto (por funcionario ou de todos)
# Examples:
# url(r'^$', 'PontoCOSGEM.views.home', name='home'),
# url(r'^PontoCOSGEM/', include('PontoCOSGEM.foo.urls')),
# Uncomment the admin/doc line below 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)),
)
视图.py
# -- coding: iso-8859-1 --
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth import authenticate, login, logout
def userLoged(request,url):
insertMessage = False
testUser = ""
try:
testUser = request.session['user']
except KeyError:
insertMessage = True
message = "É preciso estar logado para acessar esta página."
return render_to_response('loginAdmin.html',locals(),context_instance=RequestContext(request));
if testUser is not None:
return render_to_response(url,locals(),context_instance=RequestContext(request));
else:
insertMessage = True
message = "É preciso estar logado para acessar esta página."
return render_to_response('loginAdmin.html',locals(),context_instance=RequestContext(request));
def loginIndex(request):
return render_to_response('loginAdmin.html',locals(),context_instance=RequestContext(request))
def entrar(request):
insertMessage = False
message = "Erro. Usuário ou Senha incorretos."
lg = "Usuario"
passwd = "Senha"
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
request.session['user'] = user
return render_to_response('indexAdmin.html',locals(),context_instance=RequestContext(request));
else:
insertMessage = True
return render_to_response('loginAdmin.html',locals(),context_instance=RequestContext(request));
def sair(request):
insertMessage = True
message = "Saída realizada com sucesso."
logout(request)
return render_to_response('loginAdmin.html',locals(),context_instance=RequestContext(request));
def index(request):
userLoged(request,'indexAdmin.html')
# Gerência de funcionarios
def funcionariosIndex(request):
userLoged(request,'funcionarioIndex.html')
'''def funcionariosSearch(request):
def funcionariosAdd(request):
def funcionariosEdit(request):
def funcionariosDelete(request):
def funcionariosList(request):'''
# Gerência de relatórios
def relatorioIndex(request):
return HttpResponse("Menu de escolha de relatorios")
# Create your views here.
老实说,我看不到上面代码中的错误,我也不知道为什么会发生这个错误。
那么,有谁知道为什么“str”对象不可调用出现了?