Django                
            Puntos de vista
        
        
            
    Buscar..
Introducción
Una función de vista, o vista para abreviar, es simplemente una función de Python que toma una solicitud web y devuelve una respuesta web. -Django Documentación-
[Introducción] Vista simple (Hello World Equivalent)
Vamos a crear una vista muy simple para responder a una plantilla "Hello World" en formato html.
- Para hacerlo, vaya a - my_project/my_app/views.py(Aquí estamos alojando nuestras funciones de vista) y agregue la siguiente vista:- from django.http import HttpResponse def hello_world(request): html = "<html><title>Hello World!</title><body>Hello World!</body></html>" return HttpResponse(html)
- Para llamar a esta vista, necesitamos configurar un patrón de url en - my_project/my_app/urls.py:- from django.conf.urls import url from . import views urlpatterns = [ url(r'^hello_world/$', views.hello_world, name='hello_world'), ]
- Inicia el servidor: - python manage.py runserver- Ahora, si - http://localhost:8000/hello_world/, nuestra plantilla (la cadena html) se representará en nuestro navegador.
Modified text is an extract of the original Stack Overflow Documentation
        Licenciado bajo CC BY-SA 3.0
        No afiliado a Stack Overflow