Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 811 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you display python web code in Joomla?

#1
I'm building a Joomla 3 web site but I have the need to customize quite a few pages. I know I can use PHP with Joomla, but is it also possible to use Python with it? Specifically, I'm looking to use CherryPy to write some custom pieces of code but I want them to be displayed in native Joomla pages (not just iFrames). Is this possible?
Reply

#2
You can execute it through a php file. Try this:

exec("python/path/your-script.py");
Reply

#3
> It's possible, but not very efficient.
>
> You can execute a Python script from PHP using the exec() function:
> PHP Code:
>
> exec("python /path/to/python-script.py");
>
>
>
> There are also a variety of similar PHP functions that can be used to
> accomplish the same thing with minor differences to the way input and
> output are handled (passthru, system, proc_open, backticks).
>
> The Python script will be executed using its command line interface -
> not using CGI (or similar) interface as you would have if the web
> server were directly executing the Python script. This means that the
> Python script will not have access to information about the HTTP
> request - GET/POST values, the client's IP address, the page URL, etc.
> You could pass this information from PHP to Python using command line
> parameters, a pipe, a temporary file or some other form of
> inter-process communication, but you need to pass each piece of
> required information explicitly.
>
> The reason this is inefficient is because every call to exec will
> spawn a whole new process for the Python script. That's a fairly
> expensive operation to do on every HTTP request (this is why servers
> like Apache and interfaces like Fast-CGI re-use child processes and
> threads instead of creating new ones). Additionally, if you have more
> than one call to exec, every single one is going to spawn a new
> process.

Extracted from [here][1].

More info :

[To see links please register here]



[1]:

[To see links please register here]

Reply

#4
Probably the most efficient way of constructing pages from different sources (Joomla and CherryPy) is probably using Edge Side Includes [tag:esi].

Basically you run a Joomla instance that serves the documents that contain ESI tags. You run a CherryPy instance that serves the pieces you want to put on the location of the esi tags. And you run a reverse proxy that supports ESI like varnish to stitch it all together.

That may look like a lot of moving parts, but it will be responsive like... something that is really responsive. Tune the caching parts and you relieve your Joomla and database from a lot of work.

The `exec` way from the other answers will work for small python scripts that print something, but will *not* work for CherryPy.
Reply

#5
**Before considering Python**

- What are you wanting to customize? (perhaps some clever Javascript or a Joomla extension already exists)

- Is the Joomla-way not a better solution for your problem, given the fact that you're using Joomla? (change the template, or the view-templates of the modules and component in particular)

i.o.w.: do you understand Joomla *enough* to know that you need something else? See below:

**If Python is still the way to go:**

- Does your hosting support Python?

- Should you reconsider your choice of CMS?



I like your choice of CherryPy.
Reply

#6
**PHP execution of Python "scripts"**

This will work for scripts, which do stuff and return the output, not for CherryPy.

<?php
// execute your Python script from PHP
$command = escapeshellcmd('myPythonScript.py');
$output = shell_exec($command);

echo $output;

// take response content to embed it into the page
?>

**PHP to access a Python/CherryPy served website**

import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True

cherrypy.quickstart(HelloWorld())

This starts a `http://localhost:8080` and you should see `Hello world!`.

Now you could access CherryPy's output by accessing it at it's `localhost:port`.
Not good performance-wise, but works.

<?php
$output = file_get_contents('http://localhost:8080/');
echo $output;
?>

**Joomla + Ajax to access a Pyhton/CherryPy served website**

An alternative solution would be, to not use PHP to fetch the content, but to do the fetch from client-side. Basically, you would use an Ajax-Request to the CherryPy served website, to fetch it's content and embed it into the dom of the Joomla served page.

// add jQuery Ajax reqeust from your Joomla page to CherryPy
$.ajax({
url: "https://localhost:8080/", // <-- access the 2nd served website
type: 'GET',
success: function(res) {
//console.log(res);
alert(res);
$("#someElement").html(res);
}
});
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through