Django 4.1.1 редирект не работает, если request.method=='POST'
Я попытался реализовать redirect
в django 4.1.1 views. Пожалуйста, найдите следующий код.
редирект работает
def customer_registration(request):
return redirect('customer_login')
redirect not working
def customer_registration(request):
print("ASFADFAd")
if request.method == 'POST':
return redirect('customer_login')
return render(request, 'registration/registration.html')
Может ли кто-нибудь помочь, в чем проблема, я уже перерыл весь интернет, ни одно из решений не работает. Пожалуйста, помогите мне.
====== views.py ========
def HomeView(request):
form = ProductForm()
context = {
'form':form
}
return render(request,'index.html',context)
def customer_registration(request):
print("-------- GET method called ----------")
if request.method == 'POST':
print("-------- POST method called ----------")
return redirect('home')
===== urls.py =====
from django.urls import path
from .views import *
urlpatterns = [
path('home/', HomeView,name='home'),
path('', customer_registration,name='other'),
]
====== html-код ========
{% block body %}
<form action="{% url 'other' %}" method="post">
{% csrf_token %}
<p>{{form.name.label}}:{{form.name}}</p>
<p>{{form.cate.label}}:{{form.cate}}</p>
<p><button type="submit">Add</button></p>
</form>
{% endblock body %}
====== выводится после нажатия кнопки Add в терминале ========
-------- GET method called ----------
-------- POST method called ----------