I am trying to learn web programming in python. I am converting my old php-flash project into python. Now, I am confused about how to set param value and create object using python.
FYI I used a single php file, index.php to communicate with flash.swf. So, my other php files like login.php, logout.php, mail.php, xml.php etc used to be called from this.
Below is the flash object call from index.php-
<object classid="clsid:XXXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBB" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="100%" id="main" align="middle">
<param name="allowScriptAccess" value="all" />
<param name="flashvars" value= />
<param name="movie" value="flash.swf?<?=substr($_SERVER["REQUEST_URI"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);?>" />
<param name="loop" value="false" />
<param name="quality" value="high" />
<param name="bgcolor" value="#eeeeee" />
<embed src="flash.swf?<?=substr($_SERVER["REQUEST_URI"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);?>" loop="false" quality="high" bgcolor="#eeeeee" width="100%" height="100%" name="main" align="middle" allowScriptAccess="all" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
Can any geek help me out with examples how I can convert this into python? Or, any reference on how it can be done?
Cheers 🙂
Python is a general purpose language, not exactly made for web. There exists some embeddable PHP-like solutions, but in most Python web frameworks, you write Python and HTML (template) code separately.
For example in Django web framework you first write a view (view — you know — from that famous Model-View-Controller pattern) function:
And register it with URL dispatcher (in Django, there is a special file, called
urls.py):Then a
my_view.htmltemplate:While this may seem like a lot of work for such a tiny task, when you have to write something bigger than simple value-substituting script, the framework pays back. For example, you may actually write a simple blog application in less than 100 lines of code. The framework will automatically take care of URL parsing (somehow like Apache’s mod_rewrite for PHP), complex templating, database access, form generation, processing and validation, user authentication, debugging and so on.
There are a lot of different frameworks, each having its own good and bad sides. I recommend spending some time reading introductions and choosing one you like. Personally, I like Django, and had success with web.py. I’ve also heard good things about Pylons and TurboGears.
If you need something really simple (like in your example), where you don’t need almost anything, you may just write small WSGI application, which then can be used, for example, with Apache’s mod_python or mod_wsgi. It will be something like this:
To sum it up: without additional support libraries, Python web programming is somehow painful, and requires doing everything from the URI parsing to output formatting from scratch. However, there are a lot of good libraries and frameworks, to make job not only painless, but sometimes even pleasant 🙂 Learn about them more, and I believe you won’t regret it.