Python web framework php alike - php

Yes, I'm in doubt if that's a duplicate, I've searched a while but nothing exactly like this one.
I'm a hobbyist programmer, I know C++ and python well, but I'm a completely noob when it comes to web-development, it sounds more natural to me to learn PHP without frameworks, but then comes the question, is there any python module or framework that allow me to develop websites like in php-without-frameworks?, because i really prefer python over php, and also i pretend to move to Django after i learned the basics in the hard way.
I also want to code javascript and css by my own, i just want this module/framework that concatenates the native approach for web of php, but in python language 'cause i love it.
Thanks.

The python cgi module might be what you want, though it is hard to tell exactly what you want. You could also try using WSGI, which is low-level, similar in some ways to cgi. Anyway, these interfaces leave you at a pretty low level, so if you're doing this just to learn "the hard way", this is an educational way of doing that.

Related

What's the best way to run PHP within Rails?

I'd like to run PHP from within Rails, so I'd like to be able to compile both PHP and Ruby code in the .erb files. I can't figure out the best way to do this, and I'm having a hard time finding information about it without becoming completely lost.
I'm currently a Rails noob and a PHP lover so I'm using WEBrick on my Mac but Apache on my server (Windows), and I'd like to use both Rails and PHP on my Apache server if that's possible. I've heard about Passenger, but I've looked in httpd.conf on my Windows server and there's no mod_rails to be found.
I don't know if I'm ready to try installing Passenger on a Windows machine. Is that even possible? What even is Passenger?
Thanks!
While it's probably possible, it's a bad idea. The only time PHP should run with RoR is when it is an external source that is queried such as a PHP API that RoR consumes.
By combining PHP with Ruby on Rails, you are going against what Ruby on Rails is designed for and will make your code a lot less portable. The purpose or RoR is to make uniform code that follows the principles set by the creator. So, as Robert Harvey said, you should really truly embrace RoR. This will make your code easier to read for other developers and will also make asking questions on here and other forums easy since it would be a RoR question not a combined sudo question.
A good sign for not using PHP is that there are no obvious solutions out there for this that are pain free. From that, it's pretty apparent that there is no really need for it past making development easier for somebody switching frameworks.
So, I would suggest learning Ruby On Rails fully vs trying to combined them. It's going to take a while to learn all you need, but the same could be said about any framework/language.
NOTE: This might be a helpful resource if you need it http://www.amazon.com/Rails-PHP-Developers-Pragmatic-Programmers/dp/1934356042

Two ways to make python based webpages?

I wanted to try out python to create webpages instead of using php. However I came across that you need either mod_python or mod_wsgi installed to apache to make it play with python. If you now use pure, i'm not sure if it should be said pure, python code, not using any web frameworks like django. I found out that making a simple page looks differently in mod_python and in mod_wsgi.
How come?, the more I looked into python it just seemed to be a harder language to use to make webpages comparing it to php. Is there some good starting point to learn python webdevelopment?
Sorry if my question is blurry. I simply want some guidance to start out with python webdevelopment
Yes, making a webpage with python without using a web framework is harder than it is in php. This is by design, since it gives you a great deal more control over how your page interacts with the server, allowing you to build sites that scale well, among other benefits. WSGI is the modern way to interact with a server, but as you observed, it includes many of the nuts and bolts that PHP hides from the user.
If you're looking for a php-like experience for python, you might look at web.py or Flask. They are pretty minimalistic as far as frameworks go, and take care of interacting with the server but otherwise stay out of your way.
That said, you really should consider Django or another similar framework - they provide some really great benefits that help you get what would otherwise be painfully complex sites going quickly. They solve a slightly different problem and provide different solutions from the common PHP frameworks, so you should consider them even if you don't like frameworks in PHP.
If you want to do things in an even more php-like fashion, you could use CGI. It's definitely not a recommended solution, and won't teach you best practices moving forward, but it can get you started...
Really though, consider a framework. It's how most development in Python for the web is done, and you'll learn more useful skills if you develop using one.
mod_wsgi is better, because it's based on the WSGI specification, which defines the interface between web applications (or frameworks) and web servers. A WSGI app at its simplest is nothing more than a function that sends some HTTP headers via a callback and returns a string in response to information about an HTTP request. And since WSGI is implemented by many web servers, you aren't tied to Apache.
The closest you can get to pure frameworkless web development in Python is to write the WSGI app directly. This will really help you see the things that a framework like Django will obscure.
To make things easier, you might consider using Werkzeug, which is a utility library for WSGI. It has many components that are framework-like, but you can choose which ones you want and which ones you don't. For example, it has a really neat system for parsing and dispatching URLs. Werkzeug also has a simple command-line WSGI server which is probably better for development than Apache.
I'm replying to you with some advice, as someone who was in a very similar situation as you just a few months ago.
So you're using apache to host your website. That's cool. To make python play nice with apache, you're going to want to use mod_wsgi, for the reasons others have stated: seperation of concerns makes it better than cgi and mod_python is no longer being supported.
However, your impression that foregoing a framework will bring you closer to programming in "pure" python is a little bit off the mark. I shared the same opinion, and experimented with both Django and using only mod_wsgi. Let me share what I found.
Mod_wsgi is an implementation of the WSGI standard found in PEP 333. The distinction between the implementation and the standard is important. First, because it means that WSGI compliant applications will work across implementations. More importantly, it reveals something important about what WSGI is meant to do. That is, WSGI is intended a standard for writing frameworks. From the PEP:
simplicity of implementation for a framework author is not the same thing as ease of use for a web application author
and
The goal of WSGI is to facilitate easy interconnection of existing servers and applications or frameworks, not to create a new web framework.
I'm not saying that you shouldn't do something with wsgi, but you should expect to be writing a framework more than an application. If you're interested in writing a simple framework this tutorial is where I started.
However, if you're just looking to make a website, look into one of the frameworks that others have suggested. You'll still be writing python code, but the authors have worked hard to make the code you write closer connected producing websites than producing frameworks. I've personally used Django, and once it was up and running, it was rather painless to churn out interesting applications. Also, their documentation is very good, and they have a good tutorial here. That being said, Django is very fully featured, and if you're looking for something a little more minimalistic, I've heard good things about Flask, but there are lots of other options as well.
You can use ordinary CGI, which is really simple. Create a Python program that looks something like this:
#!/usr/bin/env python
import sys
sys.stdout.write("Content-type: text/html\r\n\r\n")
print("Hello <em>world</em>!")
Make this file executable (chmod +x) and put it in a directory you've configured for CGI files in your web server.
You will also find the standard Python cgi module very helpful.
If your goal is for making your python program web friendly then the answer is Cherrypy. It is a very flexible and simple framework that enables your python objects exposed in web. Check it out and it has a nice web server built-in that you don't need apache/mod_wsgi etc.,

php vs python django or something else for CMS module

We're looking to develop a CMS module for our website and I need some help in choosing the language/framework for this project. Basically we need to develop a "help' module like this one from ebay http://pages.ebay.com/help/index.html which will contain a lot of static pages with nice URLs for SEO.
The application must run fast using low computer resources.
We have been looking to use php on a custom made mvc framework but we received advice from other sources that py/django is the exactly language/framework that we need in terms of maintainability and development speed because it was developed for exactly this kind of projects so I need an expert advice on this matter with pro and cons for each choice.
It comes down to what your programmer is comfortable with. If you don't have a programmer, find one and ask him/her what she's comfortable working with. The task you're describing seems pretty simple. It can all be done with straight php, python, ruby. Having used PHP, Java and Python, I have a preference for the latter. But as I said, the task is so simple that you can do it without problem in most languages. I suspect that you'll find much more developers familiar with PHP, so you might want to look in that direction.
As far as frameworks go, there again, I don't see much that would require the raw power of an entire framework.
static pages: you need a cms, either custom built or something really lean and dead simple.
clean urls can be achieved with url rewriting (e.g. apache modrewrite directives).
Again, hire the right developer and trust his/her input. Don't go and tell him/her how to work if you don't know how it's done.
I would not say that django was specially developed for this kind of project. There are also great frameworks in PHP like the Zend Framework or symfony, among others.
In the end it comes down to what your production servers offers (but I guess you are free here) and with which programming language you feel most comfortable.
But it is true that Python's structure and style of language makes it fast to program with. (But it probably makes no difference if you are able to program PHP in your sleep ;))

Best web application language for Delphi Developers

I'm Delphi developer, and I would like to build few web applications, I know about Intraweb, but I think it's not a real tool for web development, maybe for just intranet applications
so I'm considering PHP, Python or ruby, I prefer python because it's better syntax than other( I feel it closer to Delphi), also I want to deploy the application to shared hosting, specially Linux.
so as Delphi developer, what do you choose to develop web application?
Try Morfik http://www.morfik.com/
P.S.
It looked promising a few years ago, but after I digged it deeper I must admit that it's quite limited web development environment for a very basic web development.
Why should an answer be different if the question was asked by a Delphi programmer, than a programmer from any other platform? Any decent language should be fun to learn, regardless of the tool you are using right now.
That said, I myself walked a way from Borland Pascal and Delphi (quite some time ago), over PHP and ASP.NET (using C#). Right now I am working almost exclusively on Ruby (and occasionally Rails) and I am perfectly happy with it. But, then again, it's matter of personal preference: I really enjoy Ruby's pure object-orientation and functional capabilities, as well as dynamical nature of a scripting language. So, it's all up to you and your personal preferences.
Although, one thing I can surely recommend is to stick with one of the major web-players, for pragmatic reasons: PHP, Python, Ruby, ASP.NET or possibly Java. I'm sorry to say that, but I don't think Pascaloid languages have any future anymore.
If you feel like stretching your muscles, you could try out Seaside.
Seaside's a Smalltalk framework (so working with it will feel pretty much like working with Ruby) that lets you write your website just like you'd build a desktop application. You can split your code up into components that you can assemble much like you'd work with TComponents (programmatically, at least).
I agree about Intraweb, but Delphi itself is still a good language to build websites with. You could start a CGI application or an ISAPI-extesion. You could also check out http://xxm.sf.net , it's an open-source project I started that offers a few extra's:
You can mix HTML and Delphi code into the same files (much like PHP)
These files get auto-compiled to a Delphi project so you can see the results by refreshing the web-browser (much like PHP)
You can load the library with a number of 'handlers':
there's a IInternetProtocol implementation to use with InternetExplorer directly (really handy for development
there's an ISAPI extension that loads the library (and auto-updates is, really handy for updates on live-environments)
there's a stand-alone HTTP executable or NT-Service
there's even a FireFox plugin and Apache module in the making.
PHP is the best to start, but as experienced programmer you may want to look at Python, because PHP is a C style language. Python would be easier after Pascal, I think.
Take a look at examples:
On PHP: http://en.wikipedia.org/wiki/Php#Syntax
On Python: http://en.wikipedia.org/wiki/Python_(programming_language)#Syntax_and_semantics
Note, that Ruby and Python are rarely used by them selves in web-development. Usually Django and Ruby on railes frameworks are used. In PHP there are several variants. You can code from the scratch, or also use some framework.
I used to code on PHP for about five years and now started to learn Django (python based framework) and I think it's the best thing there is. Take a look: http://djangoproject.com/
Only good answer - C# ;) Seriously ;)
Why? Anders Hejlsberg. He made it. It is the direct continuation of his work that started with Turbo Pascal and went over to Delphi... then Microsoft hired him and he moved from Pascal to C (core langauge) and made C#.
Read it up on http://en.wikipedia.org/wiki/Anders_Hejlsberg
If you come from Delphi, you will love it ;)
PHP is a pretty simple answer.
One reason is there is both Delphi4PHP (the rather cryptic IDE licensed by Embarcadero which in my estimation is really only for Web Apps (not for doing whole site)s) and PHP4Delphi (the pretty awesome Delphi Component that lets you compile your Delphi code to PHP Extensions).
I'm a long-time Delphi developer myself and had to do some web work recently, I decided to use ASP.Net with Delphi Prism and found myself right at home since I didn't have to learn a new language, just a new framework.
Actually, the answer probably is ASP.NET using C#. You'll see (ex-)Borland engineering syntax that looks quite familiar coming from Delphi. To deploy on Linux have a look at the Mono project.
I have done a fairly large (4-5 FTE) project based on webhub (www.href.com). I can certainly advise this if it is a webapp for internal use.

Should we use Pylons or PHP for our webapp?

My friend and I are planning on building a sort of a forum type of webapp.
We've used the major PHP frameworks but we're really thinking about using Python specifically the Pylons framework for our app. Although we're competent PHP programmers, we're somewhat noobs at Python (We could create practical scripts and such). But the thing is we really want to learn Python but by testing Pylons out it seems to be really difficult with all the numerous imports and all.
What would you suggest? What advice could you give to us? How would you suggest that we learn Pylons?
Decide what you want to put your focus on, being productive or learning a new language:
If you want to learn Pylons and Python, use Pylon and Python.
If you want to deliver a stable forum software, use PHP, because that's what you're competent at.
Note: I should add that this is not meant to imply that you cannot be productive with Python or Pylon in general. All I'm saying is, in your case, you will be more productive with PHP, because you know it.
Don't be scared off by imports in python. They're much more common when coding in python than PHP in general, and this is good because your namespace never gets polluted with stuff you aren't expecting, unless you do from foo import * (so don't do that). I think you'll find that the structure pylons gives you will be invaluable. There are frameworks in PHP as well, but if you want to learn python anyway, I see no reason you shouldn't dive in with Pylons.
I don't know about Pylons but I've been in a similar situation and built a site using Django. I learned enough about Python in an environment that I was familiar with (web apps) that I now go to Python as my first choice.
Many many times have we had this discussion at my job. We use PHP and everyone here would love to switch to python. Even for our new web projects PHP delivers, and since we use it every day that is what we use. Many things in PHP irk me, and I love python, that said Im a big fan of "use the best tool for the job".
Good code is possible in PHP (and horrible horrible code too), so use what is the best tool for you, and for this job. If however this webapp is a hobby and/or not mission-critical software I would fully recommend python if only to learn a new language.

Categories