Home » Questions » Computers [ Ask a new question ]

Is Python only for building backends in making websites?

Is Python only for building backends in making websites?

I have seen no website built by Python such that the url of the website contains .py at the end. I have seen only index.html and index.php, but sometimes nothing as in SO. I know that you can hide the end somehow by .htaccess -file.

Asked by: Guest | Views: 197
Total answers/comments: 5
Guest [Entry]

"Typically PHP scripts are accessed directly, similarly to a CGI script - basically you access the script like any regular file, but the web server intercepts this request, runs the script and returns the output instead of the file contents.

Most Python frameworks have their own routing systems, where you define something like..

urls = (
('^/article/(\d+)$', ArticleController),
('^/user/(.+?)$', UserController)
)

..then you would access something like..

http://example.com/router.py?uri=article/123

..and it would be run through the URL mapping defined in urls, and send the request to the appropriate class... but having the router.py part in all your URLs is a bit crappy, so you use mod_rewrite to redirect /(.*) to /router.py/$1 (either via .htaccess, your Apache configuration etc)

You can absolutely do the same thing with PHP, or any other language - this is exactly how CodeIgniter works (a PHP framework)

If you are utterly insane, you could use mod_rewrite and map /user/(\d+).py to /ViewController.php?id=$1 or something, but there's generally no point to adding a fake extension to the page (there's a few exceptions, mainly backwards compatibility, and allowing access to data in different formats in an API)

You can also do the ""PHP way"" using Python, if you write each page as a separate CGI script, just most Python frameworks tend to use the MVC (or MVC-like) setup I described above.."
Guest [Entry]

"Well, probably most people hide the extension because it is the smarter way to go. It means if you say, switched to PHP (not that you would want to...), you wouldn't have to change the extensions.

However, there are site with .py extensions (several parts of Google have it).

The better questions to ask is, why do most ASP.NET and PHP users insist on keeping the extenstions?"
Guest [Entry]

Here, you can see that Google leave the .py extension.
Guest [Entry]

Not directly related to your question, but not only websites are created with Python. The entire AI engine for EVE online (a MMP space game) is written in Python I believe.
Guest [Entry]

"Also

Google Search .py

9th Result http://schmidt.nuigalway.ie/cs103/python/graphics.py

Thats at least one website with a file that ends in .py - there are probably more."