martes, 3 de noviembre de 2020

Estableciendo rutas de URL

Para definir una ruta de URL, se emplea un decorador de python "@app.route('URL'), así como la función que manejará esa URL cuando el usuario la visite, por ejemplo:

@app.route('/')
def index():
    return 'Index Page'

@app.route('/hello')
def hello_world()
    return 'Hello, World!'

Podemos definir reglas de variables para poder recibir valores desde las URL. Así como se muestra en los siguientes ejemplos:

@app.route('/user/')
def show_user_profile(username):
    # show the user profile for that user
    return 'User %s' % escape(username)

@app.route('/post/')
def show_post(post_id):
    # show the post with the given id, the id is an integer
    return 'Post %d' % post_id

@app.route('/path/')
def show_subpath(subpath):
    # show the subpath after /path/
    return 'Subpath %s' % escape(subpath)

  1. En el primer caso, en la URL se define la variable 'username'
  2. En el segundo caso, se define la variable 'post_id' indicando que será un valor númerico (entero).
  3. En el último caso, se define la variable 'subpath' indicando que será un valor 'path'.
 Estos solo los tipos de variables a los que es posible convertir el valor pasado por la URL:

string (default) accepts any text without a slash
int accepts positive integers
float accepts positive floating point values
path like string but also accepts slashes
uuid accepts UUID strings

Necesito de tu apoyo. Con solo descargar la aplicación de Kwai y ser mi referido me estás ayudando un montón. De antemano gracias!

¡Descarga Kwai para recibir dinero! https://s.kwai.app/s/Tw9zxddS




No hay comentarios:

Publicar un comentario

¡Muchas por tu comentario! En breve estaré leyéndolo para responderte. Saludos :]

Laravel: Parte 2. Ciclo de vida de un "request"

0. public/index.php 1. bootstrap/app.php 2. Create an instance of the application / service container. 3. Kerner server / Console kernel (ap...