[web2py] Re: Understanding web2py coming from a PHP background
On Feb 21, 4:33 pm, "Jean M." wrote: > Hello, > > I am a PHP developer interested in understanding the fundamentals of web2py > framework and after reading the book and the documentation, I have some > questions which I would very much appreciate to have answered. > > 1) Why (or "is") a VPS is necessary to host web2py Python web-apps? Can it > not run under any Linux shared web-host which has python installed? web2py can run under shared hosts. The only issue is that each shared hosting is a little different therefore how depends on details. What web server do they provide? Do they provide mod_wsgi? Do they assign you a port? Do they allow long running processes? If they allow long running processes I'd suggest running web2py under your own account and configure their web server to act as proxy. > 2) Is web2py restrictive in any way? How broad is the freedom to define > custom routes, naming controllers, models and views? Can this happen > without sharing the same name? Not sure I understand the question. web2py does not impose any restriction on the number of apps. The models and controller must be valid python file names but you can use routes to map them into arbitrary URI paths. > > 3) What is web2py approach to configuration, settings and programming? CoC? > What do you think about it? What is CoC? Web2py has no configuration files except for the optional routes.py You use it when you do not want to use the default URLs. > 4) Is it possible to get web2py like PHP frameworks without installations? Web2py does not require installation. PHP does. Python does. Most system come with PHP and Python pre-installed but no web2py. You do not need to install it, you just need to download it somewhere. No need for root permission. > Do an unzip and have the folder structure to develop on without admin > interfaces and such? Again, I do not understanding the question. Anyway on any shared host you can do: wget http://web2py.com/examples/static/web2py_src.zip unzip web2py_src.zip cd web2py mkdir applications/myapp cp -r applications/welcome/* applications/myapp/ python web2py.py -a somepassword -i 0.0.0.0 -p & open http://yourhostname/myapp > 5) What would be deemed as good read for people from PHP background to > understand web2py's ways? try the above commands. Read chapter 3 of the book. Ask questions here. > Thank you
[web2py] Re: Understanding web2py coming from a PHP background
1) Python hosting is much harder than PHP hosting. While hosts that support Python should be able to support Web2py, that is not always the case because they don't support one of the web server communication mechanisms such as mod_wsgi or fastcgi. If the host supports Django apps, it should be possible to get Web2py to work. 2) It's pretty flexible but there are some restrictions enforced by Web2py, Python and/or the database. Routing is pretty flexible. 3) There isn't much of a concept of config files or anything. The optional routes.py file is sort of like a config file for routes. You can place config-like settings in models files as well. I'd say CoC has an edge. 4) Once again, setting up Python apps is harder than PHP. You don't just drop files into a folder. However, once you have Web2py up and running, then you can just drop a bundle of web2py app code in the applications directory (possibly requiring a server restart). 5) The Web2py book is the best I've seen. You can get started quickly by just downloading the Windows or Mac package and running it from your own computer. Later you can figure out how to deploy to a remote web server.
[web2py] Re: Understanding web2py coming from a PHP background
Thank you, both of you. I am really struggling to understanding the very basics of how Python Web-apps work. Your answers do help. So basically, a python app (running on web2py or not) is actually an app, and it runs on Python interpreter (just like Java apps). So they also contain, naturally, the web server or a web server interface to respond to requests. One more question: PHP allows writing stupid code. Because even if a part of the code starts performing an infinite root or somthing, the process in the end dies without affecting other connections or parts of the web-app. How does this work with Python? What happens if a part of the app, during production, goes crazy? Will the web2py app crash? Will it re-launch it self automatically or is it necessary to use something like "forever"? Thanks again!
[web2py] Re: Understanding web2py coming from a PHP background
> > 3) What is web2py approach to configuration, settings and programming? > As noted, the only real configuration file is routes.py, which is optional and used for routing (URL rewrite and routes on error). In addition to the root routes.py file in the /web2py folder, you can also have app-specific routes.py files. Also, note that model files are executed on every request (unless they are in subfolders to be executed conditionally based on the controller and/or function), so app-specific configuration-like settings are sometimes put in a model file (model files are executed alphabetically, so if you want some configuration settings to be set before any other app code runs, you might put them in a model file named 0_config.py). > CoC? > Probably more so than most Python frameworks, web2py does adopt a strong "convention over configuration" philosophy (this is in contrast to the "explicit is better than implicit" Python mantra followed by most other frameworks). See http://web2py.com/books/default/chapter/29/1#Principles. In web2py, everything has sane defaults but can be customized as needed. That's why the "hello world" is as simple as: /myapp/controllers/default.py: def index(): return dict(message='Hello World') 4) Is it possible to get web2py like PHP frameworks without installations? > Do an unzip and have the folder structure to develop on without admin > interfaces and such? > Using the "admin" interface is entirely optional. You can develop using any text editor or IDE (and, in fact, you can access most of the "admin" functionality programmatically via the gluon.admin module). > 5) What would be deemed as good read for people from PHP background to > understand web2py's ways? > A little old, but you can check out http://www.web2py.com/AlterEgo/default/show/106. That's really comparing web2py to plain PHP, not PHP MVC frameworks. Compared with PHP MVC frameworks, the biggest difference is probably just the language. You should also get a good idea about how web2py works by going through the Introduction and Overview chapters of the book, as well as http://web2py.com/books/default/chapter/29/4#Workflow and http://web2py.com/books/default/chapter/29/4#Dispatching. Anthony > > Thank you >
[web2py] Re: Understanding web2py coming from a PHP background
Not really. It's probably more like PHP than Java in that there isn't really any compiling. With more Python-based web development, you can edit files directly and the edits will be immediately visible in the browser. I'm sure some really sloppy code could cause some problems but I suspect it might be harder to do than with PHP. I don't worry about that at all and I'm a total newbie.
[web2py] Re: Understanding web2py coming from a PHP background
Is there a specific PHP framework you use? Perhaps someone could offer some comparisons based on that. I used CakePHP a lot before starting with web2py and I always compared the two in the beginning. It's a natural thing to do, I guess.
[web2py] Re: Understanding web2py coming from a PHP background
Good morning, This community is very understanding and helpful, I really appreciate the input from all of you. In PHP, I really like Kohana. All URL requests are first filtered through URL mapping settings which can be extended and set in any way necessary. Then depending on that URL routing, a controller is triggered either because it's requested via the URL or because it's set as "default". Controllers can have any name, models can have any name and they don't need to match. And it is really this simple. There is no administration, there is no set up, there is no installation. But with Python frameworks, there are many "strange" (to me that is) things. I just want to "get" the logic behind this all. In PHP, when an HTTP call is made, Apache, using the PHP, interpretes the PHP file and sends the outcome. But python, an app needs to be triggered with a specific port. Why is this so? I am not saying PHP is better. I just want to understand the "how" python functions, the fundamentals. Thank you.
[web2py] Re: Understanding web2py coming from a PHP background
Hello Anthony, thank you for your answer. Is it possible to have wildcard URL mappings without specifying the controller in the url? Say for instance if I want to have, "myurl.com/random1" and "myurl.com/r4nd0m2" to be forwarded to a single controller to perform an action within that controller, how can that be done with web2py, without permitting that controller to be called directly by myurl.com/controllername? (basically, instead of myurl.com/controllername/random1 -> myurl.com/random1) Thank you.
[web2py] Re: Understanding web2py coming from a PHP background
Massimo, I have done some more technical reading and have a direct question about web2py's basics. I would like to ask why does web2py come with it's own wcgi daemon instead of relying on an apache with embded wcgi? Thank you.
[web2py] Re: Understanding web2py coming from a PHP background
In PHP, when an HTTP call is made, Apache, using the PHP, interpretes the > PHP file and sends the outcome. But python, an app needs to > be triggered with a specific port. Why is this so? I am not saying PHP is > better. I just want to understand the "how" python functions, > the fundamentals. PHP and python behave very similar in this area, at least on the outside. There is no special port that you need to use with python. If you are referring to web2py's bundled web server's default port, than that's just a default setting, similar as you could have Apache running on some other port, not the default 80. There is absolutely no need to use web2py's bundled web server if you don't want to. It's just here for convenience. In Apache PHP is usually executed trough mod_php, mod_fcgid or other similar module. Python can be executed trough mod_fcgid or, preferably, mod_wsgi. There are other ways, I'm just stating the most obvious. I have never used the bundled web2py's server in production or even for development, just for limited testing. Based on my experience, I would advise deploying web2py with Apache or Nginx, although I'm sure other web servers could be sufficient, depending on your needs.
[web2py] Re: Understanding web2py coming from a PHP background
You can do it with URL rewrites but I'd advise against it. It's typically unnecessary and poor app design.
[web2py] Re: Understanding web2py coming from a PHP background
Web2py sounds similar but you generally skp the mapping part and just name your controller files and functions according to how you want our urls structured. It works really well if ou keep our app cleanly designed and avoid the urge to do "dumb" things. There's a little bit of "magic" getting web servers to talk to python programs but once that is set up it works similarlay to PHP. But things aren't always as simple as just dropping files in directories. A lot of add on libraries need to be installed, for example (sort of like PEAR I suppose). The one advantage of PHP is deployment ease. In all other respects python is much more pleasant, IMO.
[web2py] Re: Understanding web2py coming from a PHP background
Hello again, I have been reading further more and I found out that deploying Python applications with Apache might be a better idea than nginx due to its non-blocking nature and pythons, natural nature. Once you set up Apache to work with mod_wsgi, is it enough to upload files like in a PHP framework? What are the differences under mod_wsgi, from your experience? What do you do with the Administration section? Also, how would you personally compare web2py to cakephp? Any input would be great from your transition.
[web2py] Re: Understanding web2py coming from a PHP background
I see, but why is it poor app design? If you have, let's say, a social network and you want user profiles to be displayed directly at mysocialnetwork.com/username, then it would be necessary, Could you tell why with Python would it be a poor design? I am asking to learn the essence of the culture of this language.
[web2py] Re: Understanding web2py coming from a PHP background
> > Is it possible to have wildcard URL mappings without specifying the > controller in the url? > Say for instance if I want to have, "myurl.com/random1" and " > myurl.com/r4nd0m2" to be forwarded to a single controller to perform an > action within that controller, how can that be done with web2py, without > permitting that controller to be called directly by > myurl.com/controllername? (basically, instead of > myurl.com/controllername/random1 -> myurl.com/random1) > Yes, I suggest you look at http://web2py.com/books/default/chapter/29/4#URL-rewrite as well as the /web2py/routes.example.py and /web2py/router.example.py files. The paramater-based rewrite system works well for common simple cases, like removing the app name and default controller name (and a default function name per controller) from all URLs. For more complex cases, the pattern-based rewrite system is quite flexible. The nice thing about the rewrite systems is that they work in reverse as well -- if you use the URL() function to generate URLs, they will automatically be rewritten according to the rewrite rules. Anthony
[web2py] Re: Understanding web2py coming from a PHP background
On Wednesday, February 22, 2012 7:46:53 AM UTC-5, JeanM wrote: > > I see, but why is it poor app design? If you have, let's say, a social > network and you want user profiles to be displayed directly at > mysocialnetwork.com/username, then it would be necessary I don't think it would be poor design in that case -- that seems like a reasonable use case for rewriting. Anthony
[web2py] Re: Understanding web2py coming from a PHP background
> > PHP allows writing stupid code. Because even if a part of the code starts > performing an infinite root or somthing, the process in the end dies > without affecting other connections or parts of the web-app. > > How does this work with Python? What happens if a part of the app, during > production, goes crazy? Will the web2py app crash? Will it re-launch it > self automatically or is it necessary to use something like "forever"? > If your app code generates an error, the web2py framework will catch the error and issue an appropriate response (rollback database transactions, generate a ticket with the traceback, return an error message). The error handling behavior can be customized via routes_onerror: http://web2py.com/books/default/chapter/29/4#Routes-on-error. See also the end of this section: http://web2py.com/books/default/chapter/29/4#Dispatching. Also, assuming you're using a threaded web server (e.g., apache), an error on a given request will only affect that request's thread, not the others. If it's not an error but just something that is excessively long running, you might be able to configure the server to set a timeout per request. Anthony
[web2py] Re: Understanding web2py coming from a PHP background
> > In PHP, I really like Kohana. All URL requests are first filtered through > URL mapping settings which can be extended and set in any way necessary. > Then depending on that URL routing, a controller is triggered either > because it's requested via the URL or because it's set as "default". > Very similar in web2py, except in web2py, explicit URL mappings are optional, as there is a default mapping built in (/myapp/mycontroller/myfunction/arg1/.../argN?var1=val1&...varN=valN gets routed to the myfunction function in the mycontroller controller in the myapp application, with arg1 to argN in request.args and var1 to varN in request.vars). > Controllers can have any name, models can have any name and they don't > need to match. And it is really this simple. > Same in web2py. Models not only don't need to have the same name as controllers, but all model files are executed on every request (except for conditional models, discussed in the Workflow section of the Core chapter), so all models are available to all controllers by default. > There is no administration, there is no set up, there is no installation. > Same in web2py. > But with Python frameworks, there are many "strange" (to me that is) > things. > I think web2py tends to eschew some of those "strange" things as well. :-) Anthony
[web2py] Re: Understanding web2py coming from a PHP background
> > I have been reading further more and I found out that deploying Python > applications with Apache might be a better idea than nginx due to its > non-blocking nature and pythons, natural nature. > You don't have to stick with Apache. Nginx + uWSGI is another recommended configuration: http://projects.unbit.it/uwsgi/wiki/RunOnNginx. web2py includes a setup script: http://code.google.com/p/web2py/source/browse/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh. > Once you set up Apache to work with mod_wsgi, is it enough to upload files > like in a PHP framework? > In web2py, individual files are not directly accessible by simply specifying the filesystem path to the file in the URL, as with PHP, but I assume you don't do that with PHP MVC frameworks either. However, if you add a new file or add code to an existing file in web2py, the change will be immediately available in your web2py app without having to restart the server (e.g., if you add a new controller, you will immediately be able to access that controller within the app). > What do you do with the Administration section? > Note, the admin app is just a convenience and is not required to use web2py. Anthony
[web2py] Re: Understanding web2py coming from a PHP background
It's not a Python thing. It's a web development thing. URLs should typically correspond to one resource. That's an OK case for rewriting but quite different from the previous example. Depending on how necessary it is to avoid an extra URL segment, you could easily set it up as myserver.com/user/username without rewriting. I recall a thread awhile back on how to implement myserver.com/username and don't recall the exact outcome.