web.py wikihome of the web.py community tutorial2.esTutorial de web.py 0.2Esta es la versión en español del tutorial en Inglés de web.py v 0.2, que se encuentra en este mismo sitio. El trabajo de traducción está en desarrollo. Todo aquel que desee colaborar sólo debe crear su cuenta. Iniciando.Usted conoce Python y quiere hacer un sitio web. web.py le provee con el código para hacerlo fácilmente. Si usted quiere hacer todo el tutorial, usted necesita tener instalado Python, web.py, flup, psycopg2 y Postgres (o una base de datos equivalente y el driver de Python correspondiente). Para mayores detalles, ir a webpy.org. Si usted ya tiene funcionando un proyecto con otra versión de web.py, dele un vistazo a la información sobre migración en la página de actualización. Ya podemos comenzar. URL HandlingLa parte más importante de cualquier sitio web es la estructura de sus URLs. Los URLs de tu sitio web, no son simplemente "cosas" que los visitantes al web miran y envían por correo-e a sus amigos, ellos también proveen un modelo mental de como su sitio web funciona. En sitios populares (en inglés), tales como del.icio.us, los URLs son inclusive parte del interfase con el usuario. web.py facilita definir buenos URLs. Para comenzar una aplicación con web.py, abra un nuevo archivo de texto (vamos a llamarlo 'code.py') y tipee:
Esto importa el modulo web.py. A continuación, deberá decirle a web.py cual será la estructura de URLs. Se puede comenzar con algo sencillo como:
La primera partes es una expresión regular que coincide con un URL, como Esta linea dice que queremos que el URL Por lo tanto, todo lo que se require es escribir la clase
In our web.py code, we make the distinction between the two clear:
This Alright, now we just need to finish up with a final line telling web.py to start serving web pages:
This tells web.py to serve the URLs we listed above, looking up the classes in the global namespace of this file. Now notice that although I've been talking a lot here, we only really have five or so lines of code. That's all you need to make a complete web.py application. If you go to your command line and type:
You now have your web.py application running a real web server on your computer. Visit that URL and you should see "Hello, world!" (You can add an IP address/port after the "code.py" bit to control where web.py launches the server. You can also tell it to run a Desarrollandoweb.py also has a few tools to help us with debugging. Before the 'if name' on last line, add:
This will give you more helpful error messages. And on the last line add
This tells web.py to use the web.reloader "middleware" (middleware is a wrapper function to add some functionality to your web server) which reloads your files whenever you edit them, so that you can see the changes in your web browser right away. (For some serious changes, though, you'll still have to restart the server.) You'll probably want to take this out when you make your site public, but it's great while developing. There's also Uso de Plantillas.Writing HTML from inside Python can get cumbersome; it's much more fun to write Python from inside HTML. Luckily, web.py makes that pretty easy. **Note: web.py currently also supports Cheetah templates. Read the former tutorial for more information. Let's make a new directory for our templates (we'll call it
Or you can use web.py's templating language to add code to your HTML:
Note: Currently, four spaces are required for indentation. As you can see, the templates look a lot like Python files except for the Now go back to
This tells web.py to look for templates in your templates directory. Then change
Visit your site and it should say hello to Bob. Development tip: Add , Now change your URL line to:
and change the definition of
and delete the line setting name. Visit If you wish to learn more about web.py templates, vist the templetor page. Base de DatosAntes de la linea 'web.run' incluir:
(Cambie los valores --particularmente Cree una tabla sencilla en su base de datos:
E incluya un registro (fila):
Vuelva al código
and change back the URL handler to take just Edit
Visit your site again and you should see your one todo item: "Learn web.py". Congratulations! You've made a full application that reads from the database. Now let's let it write to the database as well. At the end of
And change your URLs list to read:
(You've got to be very careful about those commas. If you omit them, Python adds the strings together and sees Now add another class:
(Notice how we're using
Quickly:
Usted puede encontrar todos los detalles sobre lo tratado en este tutorial y lo relacionado a las funciones de web.py en la documentación. Con esto se termina este tutorial. Dele una lectura a la documentación, donde encontrará gran cantidad de material e información de lo que puede hacer con web.py |
Powered by infogami, which uses web.py. |