Update '4_Formularios'

jp.av.dev 2021-07-02 22:14:30 -04:00
parent 330ea1d9fe
commit af812a1b1f

@ -11,7 +11,7 @@
### Creacion del formulario
*/TiendaOnline/gestionPedidos/templates/busqueda_prods.html*
```
```html
<html>
<head>
<title>Búsqueda de productos</title>
@ -28,7 +28,7 @@
### Creación vista formulario
*gestionPedidos/views.py*
```
```py
from django.shortcuts import render
# Create your views here.
@ -39,7 +39,7 @@ def busqueda_productos(request):
### Restistrar url *(path)*
*urls.py*
```
```py
...
from gestionPedidos import views
@ -51,7 +51,7 @@ urlpatterns = [
### Crear vista para el *submit* 'buscar'
*gestionPedidos/views.py*
```
```py
...
from django.http import HttpResponse
@ -63,7 +63,7 @@ def buscar(request):
### Registrar url
*urls.py*
```
```py
...
urlpatterns = [
@ -79,7 +79,7 @@ urlpatterns = [
### Busqueda en BBDD
*views.py*
```
```py
...
from gestionPedidos.models import Articulos
@ -101,7 +101,7 @@ def buscar(request):
*resultado_busqueda.html*
```
```html
<body>
<p>Estás buscando <strong>{{query}}</strong></p>
{% if articulos %}
@ -120,7 +120,7 @@ def buscar(request):
### Limitar cantidad de caracteres en busqueda
*views.py*
```
```py
...
def buscar(request):
@ -137,11 +137,8 @@ def buscar(request):
### Formulario de contacto
*views.py*
*contacto.html*
```
```html
<body>
<h1>Formulario de contacto</h1>
<form action="/contacto/" method="POST">
@ -160,13 +157,13 @@ def buscar(request):
*This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.*
*gracias.html*
```
```html
...
<h1>Gracias por contactarnos</h1>
...
```
*views.py*
```
```py
...
def contacto(request):
if request.method == "POST":
@ -175,7 +172,7 @@ def contacto(request):
```
*urlpatterns urls.py*
```
```py
...
path('contacto/', views.contacto),`
...