![]() |
|
|
|||||||
![]() |
Python - Re: Web development with Python 3.1 |
|
|
Thread Tools | Search this Thread |
|
|
#11 |
|
> A webframework is *written* in python. Your whole line of argumentation
> boils down to "I can write things myself in python, why use > libraries/frameworks". Yes. You can also delete your standard-lib, and code > everything in there yourself - with the same argument. > > Using a framework is about proven solutions for common problems, letting you > focus on working on your actual application code. > While I know that to be true in the general sense, from what I've looked at Django and other frameworks it seems that the web frameworks push the coder to use templates, not letting him near the HTML. For instance, I was looking for a class / framework that provided a proven method of decoding cookies (setting them is no problem), decoding POST and GET variables, escaping variables for safe entry into MySQL, and other things. Django and the other frameworks seem to force the user to use templates. I just want the functions, and to print the HTML as stdout to the browser making the request. I had to settle on PHP to do this, which admittedly is what PHP was invented to do. However, for obvious reasons, I would have prefered to code in Python. In fact, I still would. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Dotan Cohen |
|
|
|
|
#12 |
|
Posts: n/a
|
> While I know that to be true in the general sense, from what I've
> looked at Django and other frameworks it seems that the web frameworks > push the coder to use templates, not letting him near the HTML. > > For instance, I was looking for a class / framework that provided a > proven method of decoding cookies (setting them is no problem), > decoding POST and GET variables, escaping variables for safe entry > into MySQL, and other things. Django and the other frameworks seem to > force the user to use templates. I just want the functions, and to > print the HTML as stdout to the Â*browser making the request. I had to > settle on PHP to do this, which admittedly is what PHP was invented to > do. However, for obvious reasons, I would have prefered to code in > Python. In fact, I still would. > I should probably expand on this: How can I get an array with all the GET variables in Python? How can I get an array with all the POST variables in Python? How can I get an array with all the COOKIE variables in Python? How can I get the request URI path (everything after http://[www.?]example.com/)? That's all I want: no templates and nothing between me and the HTML. The HTTP headers I can output to stdout myself as well. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Dotan Cohen |
|
|
|
#13 |
|
Posts: n/a
|
Dotan Cohen schrieb:
>> While I know that to be true in the general sense, from what I've >> looked at Django and other frameworks it seems that the web frameworks >> push the coder to use templates, not letting him near the HTML. >> >> For instance, I was looking for a class / framework that provided a >> proven method of decoding cookies (setting them is no problem), >> decoding POST and GET variables, escaping variables for safe entry >> into MySQL, and other things. Django and the other frameworks seem to >> force the user to use templates. I just want the functions, and to >> print the HTML as stdout to the browser making the request. I had to >> settle on PHP to do this, which admittedly is what PHP was invented to >> do. However, for obvious reasons, I would have prefered to code in >> Python. In fact, I still would. >> > > I should probably expand on this: > > How can I get an array with all the GET variables in Python? > How can I get an array with all the POST variables in Python? > How can I get an array with all the COOKIE variables in Python? > How can I get the request URI path (everything after > http://[www.?]example.com/)? > > That's all I want: no templates and nothing between me and the HTML. > The HTTP headers I can output to stdout myself as well. Again: if you insist on doing everything yourself - then of course any library or framework isn't for you. But then do you deal with headers correctly? Do you respect character encodings? Form-encodings? Is your generated HTML valid? Are timestamp-formats generated according to RFCs for your cookies? Do you parse content negotiation headers? I think you underestimate the task it is to make a webapplication good. And even if not, what you will do is ... code your own webframework. Because there is a lot of boilerplate otherwis. If that's a learning-experience your after, fine. Besides, yes, you can get all these things nonetheless. You just don't need them most of the time. And at least pylons/TG2 lets you return whatever you want instead, as a string. Not via "print" though - which is simply only for CGI, and no other means (e.g. mod_wsgi) of python-web-programming. Diez Diez B. Roggisch |
|
|
|
#14 |
|
Posts: n/a
|
Dotan Cohen a écrit :
>> declarative mapping of urls to code > > Apache does this, unless I am misunderstanding you. Using url rewriting ? Yes, fine. Then tell me how you implement "reverse" url generation (like Django or Routes do). > >> of code to templates > > Those who code in HTML don't need this. ??? > In any case it's not hard to > call a function in a class that writes the HTML before the content, > then write the content, then call another function that writes the > HTML after the content. Hmmm, yummy ! And SO maintainable... > This is how my sites are run, though in PHP > instead of Python. No prepackaged templates. PHP *is* a template language. (snip) > I would really like to know what else. So far, I am not convinced that > a framework offers anything that is not already easily accomplished in > Python. Given that we're talking about Python frameworks, it seems obvious that what they do can be accomplished in Python. Now the question is how much you like to write the same boring and error-prone boilerplate code project after project... Bruno Desthuilliers |
|
|
|
#15 |
|
Posts: n/a
|
Dotan Cohen a écrit :
>> Well, yes- but it's also DRY, and while DRTW (like the acronym, btw) >> helps to prevent your code from being unreadable to someone else, >> DRY helps to ensure that when you have to change something you >> don't have to worry about changing it in 37 and a half other places >> at the same time. Especially given how notoriously difficult it is to >> do automated testing for web development, that's essential. >> > > That's what classes are for, no? Reuse code. Nope. "classes" are an artifact of one possible approach of OOP, period. > I fail to see how using a > framework would reduce the need to use classes, Why should it ? Bruno Desthuilliers |
|
|
|
#16 |
|
Posts: n/a
|
Dotan Cohen a écrit :
>> A webframework is *written* in python. Your whole line of argumentation >> boils down to "I can write things myself in python, why use >> libraries/frameworks". Yes. You can also delete your standard-lib, and code >> everything in there yourself - with the same argument. >> >> Using a framework is about proven solutions for common problems, letting you >> focus on working on your actual application code. >> > > While I know that to be true in the general sense, from what I've > looked at Django and other frameworks it seems that the web frameworks > push the coder to use templates, not letting him near the HTML. Well... there must be a reason, for sure... No ? > Django and the other frameworks seem to > force the user to use templates. Not at all. Nothing prevents you from shooting yourself in the foot and generating HTML "by hand" in your view functions (or request handler methods etc, depending on the framework). This is just plain stupid wrt/ readability, maintainability, reuse and whatnot, but hey, if you want to waste your time, please do. As far as i'm concerned, I'm very happy to let the HTML coder write the HTML part and the application programmer write the applicative part - even when I end up wearing both caps. > I just want the functions, and to > print the HTML as stdout to the browser making the request. I had to > settle on PHP to do this, Why so ? Almost any programming language can do CGI. Bruno Desthuilliers |
|
|
|
#17 |
|
Posts: n/a
|
Hello, Dotan
On Wed, 28 Oct 2009 10:26:22 +0200 Dotan Cohen <> wrote: > I should probably expand on this: > > How can I get an array with all the GET variables in Python? > How can I get an array with all the POST variables in Python? > How can I get an array with all the COOKIE variables in Python? > How can I get the request URI path (everything after > http://[www.?]example.com/)? > > That's all I want: no templates and nothing between me and the HTML. > The HTTP headers I can output to stdout myself as well. $python >>help(cgi) >>help(cgitb) >>help(Cookie) >>help(urlparse) >>help(os.environ) GET variables: ------------------------------------------------------------------------- import os,cgi if os.environ.has_key('QUERY_STRING'): getv = cgi.parse_qs(os.environ['QUERY_STRING']) print getv.keys() Other examples is very simple too... -- Mikhail M.Smagin <> Mikhail M.Smagin |
|
|
|
#18 |
|
Posts: n/a
|
>> I should probably expand on this:
>> >> How can I get an array with all the GET variables in Python? >> How can I get an array with all the POST variables in Python? >> How can I get an array with all the COOKIE variables in Python? >> How can I get the request URI path (everything after >> http://[www.?]example.com/)? >> >> That's all I want: no templates and nothing between me and the HTML. >> The HTTP headers I can output to stdout myself as well. > > Again: if you insist on doing everything yourself - then of course any > library or framework isn't for you. > I insist on handling the HTML myself. As for converting the request variables into Python variables, if a class/framework makes that easier then I would gladly use it. My question was serious. How can I do those things? > But then do you deal with headers correctly? Yes, so far as I know. This is actually simpler than the HTML, just be careful not to output two newline characters in sequence (thereby ending the header). > Do you respect character > encodings? Yes! UTF-8 from database to scripting language to HTTP request. > Form-encodings? Yes, UTF-8 the in the other direction. However, as form data can be spoofed, I would like a function that checks it. Does Python have such a function? What class does? > Is your generated HTML valid? Naturally, even though this is not a Python issue. > Are > timestamp-formats generated according to RFCs for your cookies? Yes, this is not a problem. Is there some gothcha that I am unaware of? > Do you parse > content negotiation headers? > No. I hate sites that do that. If the page is available in another language, their is a link in the corner. > I think you underestimate the task it is to make a webapplication good. Probably, but that would not depend on the scripting language. I make bad webapplications in PHP too! > And > even if not, what you will do is ... code your own webframework. That is why I am looking for a class that handles the backend stuff, but lets _me_ handle the HTML. > Because > there is a lot of boilerplate otherwis. If that's a learning-experience your > after, fine. > > Besides, yes, you can get all these things nonetheless. You just don't need > them most of the time. > > And at least pylons/TG2 lets you return whatever you want instead, as a > string. Not via "print" though - which is simply only for CGI, and no other > means (e.g. mod_wsgi) of python-web-programming. > I am trying to follow you here. What is "return whatever you want"? Return HTML to stdout to be sent to the browser? -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Dotan Cohen |
|
|
|
#19 |
|
Posts: n/a
|
2009/10/28 Bruno Desthuilliers <>:
> Dotan Cohen a écrit : >>> >>> declarative mapping of urls to code >> >> Apache does this, unless I am misunderstanding you. > > Using url rewriting ? Yes, fine. Then tell me how you implement "reverse" > url generation (like Django or Routes do). I have no idea what reverse url generation is. I assume that the user will call http://example.com/path/to/script.py...llo&var2=world script.py would live in /home/user/site-name/public_html/path/to/ >>> of code to templates >> >> Those who code in HTML don't need this. > > ??? > I would prefer to output everything from <html> to </html> with print statements. I don't want some framework wrapping my output in tags, I want the tags to be part of the output. >> In any case it's not hard to >> call a function in a class that writes the HTML before the content, >> then write the content, then call another function that writes the >> HTML after the content. > > Hmmm, yummy ! Â*And SO maintainable... > Yes, why not? >> This is how my sites are run, though in PHP >> instead of Python. No prepackaged templates. > > PHP *is* a template language. > This is, in general what I'm doing: <?php // process GET POST and cookie variables, deal with mysql if needed $title="blah"; include_once"/path/to/headerFile"; print "$content"; include_once"/path/to/footerFile"; exit(); ?> >> I would really like to know what else. So far, I am not convinced that >> a framework offers anything that is not already easily accomplished in >> Python. > > Given that we're talking about Python frameworks, it seems obvious that what > they do can be accomplished in Python. Now the question is how much you like > to write the same boring and error-prone boilerplate code project after > project... > Like I said before, I don't want to have to maintain the functions that turn the HTTP environment into Python variables, or the code that manages database connections. Functions that escape data to be sent to MySQL (to prevent sql injection) would be nice. Other than that, it's all on me. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Dotan Cohen |
|
|
|
#20 |
|
Posts: n/a
|
>> While I know that to be true in the general sense, from what I've
>> looked at Django and other frameworks it seems that the web frameworks >> push the coder to use templates, not letting him near the HTML. > > Well... there must be a reason, for sure... No ? > Ö¹Yes, but I don't like it. >> Django and the other frameworks seem to >> force the user to use templates. > > Not at all. Nothing prevents you from shooting yourself in the foot and > generating HTML "by hand" in your view functions (or request handler methods > etc, depending on the framework). How is this done in Django, then? > This is just plain stupid wrt/ > Â*readability, maintainability, reuse and whatnot, but hey, if you want to > waste your time, please do. As far as i'm concerned, I'm very happy to let > the HTML coder write the HTML part and the application programmer write the > applicative part - even when I end up wearing both caps. > I've done stupider things. >> I just want the functions, and to >> print the HTML as stdout to the Â*browser making the request. I had to >> settle on PHP to do this, > > Why so ? Almost any programming language can do CGI. And I settled on PHP because it does what I need. However, I would prefer to move it to Python for the benefit of using the same language in the different places that I code for (such as personal applications for the desktop, pyqt). -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Dotan Cohen |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Software Development Company | hanusoft | Software | 0 | 12-23-2007 06:52 AM |
| Regarding MSTS SharePoint 2007 and WSS 3.0 Application Development | Shiva | MCTS | 6 | 12-06-2007 06:32 AM |
| Business Software Development | hanusoft | Software | 0 | 11-16-2007 01:21 PM |
| DVD Verdict reviews: ARRESTED DEVELOPMENT: SEASON TWO and more! | DVD Verdict | DVD Video | 0 | 10-11-2005 09:16 AM |
| The Practice Test Package Development: A New Service on the Certification Market | David Johnson | A+ Certification | 0 | 01-19-2005 10:52 AM |