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 ### Creacion del formulario
*/TiendaOnline/gestionPedidos/templates/busqueda_prods.html* */TiendaOnline/gestionPedidos/templates/busqueda_prods.html*
``` ```html
<html> <html>
<head> <head>
<title>Búsqueda de productos</title> <title>Búsqueda de productos</title>
@ -28,7 +28,7 @@
### Creación vista formulario ### Creación vista formulario
*gestionPedidos/views.py* *gestionPedidos/views.py*
``` ```py
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
@ -39,7 +39,7 @@ def busqueda_productos(request):
### Restistrar url *(path)* ### Restistrar url *(path)*
*urls.py* *urls.py*
``` ```py
... ...
from gestionPedidos import views from gestionPedidos import views
@ -51,7 +51,7 @@ urlpatterns = [
### Crear vista para el *submit* 'buscar' ### Crear vista para el *submit* 'buscar'
*gestionPedidos/views.py* *gestionPedidos/views.py*
``` ```py
... ...
from django.http import HttpResponse from django.http import HttpResponse
@ -63,7 +63,7 @@ def buscar(request):
### Registrar url ### Registrar url
*urls.py* *urls.py*
``` ```py
... ...
urlpatterns = [ urlpatterns = [
@ -79,7 +79,7 @@ urlpatterns = [
### Busqueda en BBDD ### Busqueda en BBDD
*views.py* *views.py*
``` ```py
... ...
from gestionPedidos.models import Articulos from gestionPedidos.models import Articulos
@ -101,7 +101,7 @@ def buscar(request):
*resultado_busqueda.html* *resultado_busqueda.html*
``` ```html
<body> <body>
<p>Estás buscando <strong>{{query}}</strong></p> <p>Estás buscando <strong>{{query}}</strong></p>
{% if articulos %} {% if articulos %}
@ -120,7 +120,7 @@ def buscar(request):
### Limitar cantidad de caracteres en busqueda ### Limitar cantidad de caracteres en busqueda
*views.py* *views.py*
``` ```py
... ...
def buscar(request): def buscar(request):
@ -137,11 +137,8 @@ def buscar(request):
### Formulario de contacto ### Formulario de contacto
*views.py*
*contacto.html* *contacto.html*
``` ```html
<body> <body>
<h1>Formulario de contacto</h1> <h1>Formulario de contacto</h1>
<form action="/contacto/" method="POST"> <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.* *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* *gracias.html*
``` ```html
... ...
<h1>Gracias por contactarnos</h1> <h1>Gracias por contactarnos</h1>
... ...
``` ```
*views.py* *views.py*
``` ```py
... ...
def contacto(request): def contacto(request):
if request.method == "POST": if request.method == "POST":
@ -175,7 +172,7 @@ def contacto(request):
``` ```
*urlpatterns urls.py* *urlpatterns urls.py*
``` ```py
... ...
path('contacto/', views.contacto),` path('contacto/', views.contacto),`
... ...