Django Functional Views - 4
View:
def product_list(request):
product_name = request.GET.get('product_name')
print(product_name)
print(request.user)
if request.method == "POST":
print(request.POST)
else:
print(request.GET)
return render(request=request, template_name="products.html")
Html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<div class="container mt-5">
<h3 class="text-center">Ürün Ekle</h3>
<form action="{% url 'products' %}" method="POST">
{% csrf_token %}
Ürün adı <input type="text" name="product_name" class="form-control">
Ürün Adet <input type="number" name="product_count" class="form-control">
<input type="checkbox" name="checkbox" value="1">Ch 1 <br>
<input type="checkbox" name="checkbox" value="2">Ch 2
<input type="submit" class="form-control">
</form>
</div>
{% if request.resolver_match.url_name == "products" %}
fasdfasdf
{% endif %}
</body>
</html>
Yorumlar
Henüz Hiç Yorum Yapılmamış