1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Submit button doesn't refresh page and send POST request

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I'm doing registration on Django. I made a form, added a button that should refresh the page and send a POST request. But the button does not update the page and does not send the request. I doesn't have any scripts on JavaScript. My views.py code:

    from django.shortcuts import render, redirect
    from .models import User
    from .forms import UserForm
    from django.views import View

    def index(request):
    return render(request, 'index.html')

    def inn(request):
    return render(request, 'in.html')

    class PostCreate(View):
    def up(self, request):
    form=UserForm(request.POST)
    if form.is_valid():
    form.save()
    return redirect('home')

    def down(request):
    return render(request, 'up.html')`


    My forms.py code:

    from .models import User
    from django.forms import ModelForm

    class UserForm(ModelForm):
    class Meta:
    model=User
    fields=['NickName', 'Email', 'Password']`


    And HTML: HTML

    I'm tried to search any information on internet, but I'm found only about event.preventDefault() and type='button'. But I doesn't have any scripts and my type is 'submit'

    Continue reading...

Compartilhe esta Página