Error NoReverseMatch on django


I am receiving the following error on my page made with django.


Reverse for 'subscribed' with keyword arguments' {'name': u'ImHarvol '}' not found. 1 pattern (s) tried: ['edoras / newsletter / subscribed $']

The page consists of a form, which after completing it, has to redirect you to the view subscribed . :

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

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^newsletter$', views.newsletter, name='newsletter'),
    url(r'^newsletter/suscrito$', views.suscrito, name='suscrito'),
] :

    # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render

### Create your views here.

from django.shortcuts import get_object_or_404, redirect
from .forms import SuscripcionForm
from .models import Suscripcion
from .modulos import *

def index(request):
#   return render(request, 'edoras/index.html', {})
    return redirect(newsletter)

def newsletter(request):
#   return render(request, 'edoras/newsletter.html', {})
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
        ip = request.META.get('REMOTE_ADDR')

    if request.method == "POST":
        form = SuscripcionForm(request.POST)
        if form.is_valid():
            suscripcion =
            suscripcion.ip = ip
            fsuscripciones = open("/home/imharvol/web/edoras/botsuscripciones/twitters.txt", "a")
            fsuscripciones.write('\[email protected]'+suscripcion.nombre_twitter)
            return redirect('suscrito', nombre=suscripcion.nombre_twitter)
        form = SuscripcionForm()

    return render(request, 'edoras/newsletter.html', {'form': form})

def suscrito(request, nombre):
    return render(request, 'edoras/suscrito.html', {'nombre': nombre})

I guess the error is due to this line return redirect('suscrito', nombre=suscripcion.nombre_twitter) . There I am trying to send the name that they have put in the form, to the subscribed view, to then print their name.

asked by ImHarvol 15.08.2017 в 15:52

1 answer


It is that you are passing an argument nombre that is not configured. You just have to remove it from the redirect function.

But if you want to use the argument for your template, you would have to change your url to something like this:

url(r'^newsletter/suscrito/(?P<nombre>\w+)$', views.suscrito, name='suscrito'),

I have not verified it, but the group expression nombre must ensure that the argument is well formed. In this example, accept any word.

answered by 15.08.2017 в 16:56