NoReverseMatch at / accounts / register u'cuentas' is not a registered namespace

2

I'm working with Django 1.10 and I just created a user registry but when I click save it does not redirect me to the cuentas:home page:

User registration

<form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Guardar </button>
</form>

Primary URLs

from django.conf.urls import url, include
from django.contrib import admin

from django.contrib.auth.views import login

urlpatterns = [
    url(r'^login/$', login, {'template_name': 'login.html'},name='login'),
    url(r'^cuentas/', include('cuentas.urls'), name='cuentas'),
    url(r'^admin/', admin.site.urls),
]

Application URLs

from django.conf.urls import url
from . import views

from .views import RegistroUsuario, home

urlpatterns = [
    #url(r'^$', views.index, name='index'),
    url(r'^registrar', RegistroUsuario.as_view(), name='registrar'),
    url(r'^home', home , name='home')
]

View

from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.views.generic import CreateView
from django.urls import reverse_lazy

from django.shortcuts import render
from .models import Cuenta


def index(request):

    cuentas = Cuenta.objects.all()

    template = 'base.html'
    titulo = 'Pagina base'
    context = {
        'titulo': titulo,
        'cuentas': cuentas
    }
    return render(request, template, context)


def login(request):
    template = 'login.html'
    titulo = 'Pagina base'
    context = {
        'titulo': titulo
    }
    return render(request, template, context)


def home(request):
    template = 'home.html'
    titulo = 'Pagina base'
    context = {
        'titulo': titulo
    }
    return render(request, template, context)


class RegistroUsuario(CreateView):
    model = User
    template_name = "registrar_usuario.html"
    form_class = UserCreationForm
    success_url = reverse_lazy('cuentas:home')
    
asked by Marcos Mauricio 20.02.2018 в 16:03
source

1 answer

2

The problem is the definition of your URLs in this part:

urlpatterns = [
    url(r'^login/$', login, {'template_name': 'login.html'},name='login'),
    url(r'^cuentas/', include('cuentas.urls'), name='cuentas'),
    url(r'^admin/', admin.site.urls),
]

You seem to be confusing name with namespace . The name parameter is a parameter of the url() function, while the namespace parameter is a parameter of the include() function. Therefore, the correct code should be:

urlpatterns = [
    url(r'^login/$', login, {'template_name': 'login.html'},name='login'),
    url(r'^cuentas/', include('cuentas.urls', namespace='cuentas')),
    url(r'^admin/', admin.site.urls),
]
    
answered by 20.02.2018 / 17:26
source