在Django Project的urls.py中,“'str'对象不可调用”

时间:2013-10-08 14:22:07

标签: django django-urls

当我访问项目的url“localhost:8000 / adminPonto”(我是brazillian)时,我的Django项目中的TypeError 'str'对象无法调用。它遵循 urls.py (在错误中)和 adminApp.views (与urls.py相关的代码,因此与错误相关的代码)的代码:< / p>

urls.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)),
)

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)), )

views.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'对象不可调用正在出现?

1 个答案:

答案 0 :(得分:0)

多行评论如'''评论文字'''可能会导致麻烦。

尝试评论

中的五行
'''(r'^adminPonto/funcionarios/search/$',adminApp.views.funcionariosSearch), # Procura por funcionario

用'#'告诉它是否有帮助。