python - 'str' object not callable -
i have problem in django:
'str' object not callable
code:
urls.py app usuarios:
from django.conf.urls import patterns, include, url django.contrib.auth.views import login, logout_then_login usuarios.views import registro urlpatterns = patterns('', url(r'^login/$', 'django.contrib.auth.views.login', {'template_name':'registration/login.html'}, name='login'), url(r'^cerrar/$', 'django.contrib.auth.views.logout_then_login', name='logout'), url(r'^registro/$', 'registro', name='registro'), )
views.py
from django.http import httpresponse, httpresponseredirect django.contrib.auth import authenticate, login, logout django.core.context_processors import csrf #importar el formulario de registro usuarios.forms import registrousuario def registro(request): if request.user.is_anonymous(): if request.method == 'post': form = registrousuario(request, post) if form.is_valid(): form.save() return httpresponse('usuario creado sin problemas.') else: form = registrousuario() context = {} context.update(csrf(request)) context['form'] = form #pasar el context al template return render_to_response('registro.html', context) else: return httpresponseredirect('/')
forms.py:
from django import forms django.contrib.auth.models import user django.contrib.auth.forms import usercreationform class registrousuario(usercreationform): class meta: fields = ('first_name', 'last_name', 'email', 'username', 'password1', 'password2')
i not worked django , truth error not telling me might wrong.
environment: request method: request url: http://127.0.0.1:8000/usuarios/registro/ django version: 1.6.2 python version: 2.7.6 installed applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'usuarios') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware') traceback: file "c:\python27\lib\site-packages\django\core\handlers\base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) exception type: typeerror @ /usuarios/registro/ exception value: 'str' object not callable
you named view incorrectly in url dispatch:
from usuarios.views import registro urlpatterns = patterns('', # ... url(r'^registro/$', 'registro', name='registro'),
here 'registro'
not name django can import (it not full module path), nor did specify prefix import (the first argument patterns()
empty string ''
).
you should either give actual view object (that imported here), or give name full module path.
so pick 1 of:
from usuarios.views import registro urlpatterns = patterns('', # ... url(r'^registro/$', registro, name='registro'),
or
urlpatterns = patterns('', # ... url(r'^registro/$', 'usuarios.views.registro', name='registro'),
the first option passes actual view function register (which works because imported already).
the second option gives full path module in addition view name; django can import (it looks .
in string determine if can imported).
Comments
Post a Comment