dimanche 24 mai 2015

Django - NoReverseMatch error in a simple form

i am stuck with this error:

"Reverse for 'create' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$create$']"

I can't see where the problem is.

Here is my index.html that contain my form:

<form action="{% url 'log:create' %}" method="post">
//...
</form>

Here is my urls.py :

urlpatterns = [
 url(r'^$', views.index, name='index'),
 url(r'^login$', views.login, name='login'),
 url(r'^logout$', views.logout, name='logout'),
 url(r'^create$', views.create, name='create'),
 ]

Then I defined my function create in the views.py :

def create(request):
  if request.method == "POST" and request.POST['name'] and request.POST['password']:
      name_p = escape(request.POST['name'])
      pass_p = escape(request.POST['password'])
      try:
          login = User.objects.get(username=name_p)
      except:
          user = User.objects.create_user(name_p, name_p+'@email.com', pass_p)
          user.save()
          return HttpResponseRedirect('log:index')
      else:
          return render(request, 'log/index.html', {'error_message' : 'The login you chose already exists',})
  else:
      return render(request, 'log/index.html', {'error_message' : 'You did\'t fill the entire form',})

I don't know where is my mistake because the form is a simple one with no arguments passed and the regular expression in the url is a simple one too. It must be a problem in my function I think. If someone could lead me to the right path to fix this kind of error that would be great ;)




Aucun commentaire:

Enregistrer un commentaire