GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing webwareforpython.github.io — Quickstart — Webware for Python 3 3.1.0 documentation Quickstart¶In this chapter we will show how you can create and run a “hello world” application with Webware for Python 3, and try out the example servlets provided with Webware. In the next chapter, we will then go into a little bit more detail and create a slightly more complex application. We assume you have already installed Webware for Python 3 into a virtual environment as explained in the chapter on Installation. The Webware CLI¶Webware for Python 3 comes with a command line tool named “webware” that helps creating a new projects and starting a development web server. You can run webware --help Remember that you need to activate the virtual environment where you installed Webware for Python 3 first if you haven’t installed it globally. Creating a Working Directory¶You can use the subcommand webware make --help Let’s start a simple “hello world” project using the webware make HelloWorld You should see some output on the console explaining what has been created for your. Particularly, you should now have a subdirectory “HelloWorld” in your current directory. Each Webware application consists of one ore more “contexts”, which correspond to different URL prefixes. Some contexts such as the “example” and “admin” contexts are already provided with Webware for Python by default. Running the Webware Examples¶You need to cd HelloWorld Now you can run the application with the following command: webware serve -b The “serve” subcommand will start the development server, and the You should also a link to the “Exmples” context located at the URL Try one of the example now, e.g. the CountVisits servlet. This example demonstrates how to use Webware Sessions to keep application state. In the navigation bar you will also find a link to view the source of CountVisits. You will find that the source code for this servlet is very simple. It inherits from the Using the Admin Context¶Besides the “Examples” context, Webware for Python also provides an “Admin” context out of the box. By default it is located at the URL You will find the configuration file in the You can use the webware serve -r The webware serve --help After adding an admin password, you should be able to log in to the admin context using the user name “admin” and the admin password you selected. In the navigation bar on the left side you now see several admin servlets. For example, the “Plug-ins” servlet lists all the Webware for Python plug-ins currently installed. A “Hello World” Example¶The A newly created default context already contains one servlet Let’s add another very simple servlet self.writeln('<ul><li><a href="HelloWorld">Hello, World!</a></li></ul>') Everything that you pass to the When you navigate to the start page of your application, you should now already see this link. For now, you will get an “Error 404” when trying to click on this link. In order to make it operational, save the following file as from Page import Page class HelloWorld(Page): def title(self): return 'Hello World Example' def writeContent(self): self.writeln('<h1>Hello, World!</h1>') Now the link on the start page should work and you should see “Hello World!” on your page and whatever more you want to write in the writeContent() method above. If you want to change the style of the page, use different colors or larger letters, you should use the def writeStyleSheet(self): self.writeln('''<style> h1 { color: blue; font-size: 40px; font-family: sans-serif; text-align: center; } </style>''') |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |