Reverse for 'success' with arguments '()' and keyword arguments '{}' not found

I'm starting my Django (1.5) project and When I register the url of a view I get this error!

The Html

<form action="{% url 'MainApp:success' %}" method="POST" class="form-horizontal">
    {% csrf_token %}
    <div class="control-group">
    <label class="control-label" for="inputText">Nombres</label>
    <div class="controls">
      <input type="text" id="inputText" placeholder="Nombres" name="nombre" required>
    </div>
</div>
</form>

App.view

from django.shortcuts import render, render_to_response
from django.contrib.auth.models import User

def index(request):
     return render_to_response('TeamCheetah/index.html')

def auth(request):
     if request.POST['registra'] is 'registra':
         user = User.objects.create_user(request.POST['nombre'], request.POST['email'], request.POST['pass'])
         user.last_name = request.POST['apellido']
         user.save()
     return render_to_response('TeamCheetah/Actions.html')

App.urls

from django.conf.urls import patterns, url

from MainApp_TeamCheetah import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^success/$', views.auth, name='success'),
)

Mysite.urls

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^$', include('MainApp_TeamCheetah.urls', namespace="MainApp")),
    url(r'^admin/', include(admin.site.urls)),
)

It marks the error in the form. I believe it's related with the view auth i created because when I use the action: index in the form, it works perfectly fine.

Upvotes: 2

Views: 896

Answers (1)

Simeon Visser
Simeon Visser

Reputation: 122506

Two things:

  • url tags are written without ', so {% url MainApp:success %} when you're linking to a URL by name and not by view path. This shouldn't affect things but that's how they're canonically written.

  • More importantly, the following line has a regex that ends with a $ which means it won't match to any URLs that have something after that:

    url(r'^$', include('MainApp_TeamCheetah.urls', namespace="MainApp")),

    That would explain why it does match index but not success.

Upvotes: 1

Related Questions