executing a python script in Django - python

I made a python script (a URL extractor with selenium)(myurl.py) and I want to print the output URL into an HTML button. I'm using Django.

If you use Djano I don't know why you ask about PHP, but:
You can save this output in file via Python and then get its content by PHP.
You can use database. By Python script save output to record, then display its by PHP
Of course it's possible only when you are executing python script on the server where website is installed

Related

Is it possible to display a python result with react?

I want to write a program using python as logic, because of the extensive libraries available in python suited for this project, and to develop the UI using react.
Is this at all possible, or is there a different method which is easier?
if you want to use react as a front end for a website, you could run python as the back end using something like flask or Django. Python can't be run in the browser, you'll need to run python on a server or run in locally on your machine if the project is just for you.

Create Google Extension that can process with Python

Halo, I need to develop a Google extension that able to link with python. I already write the process code in the python, all I need is a extension that can scrape the Twitter ID and Tweet, and process through the python and send back the result from python to extension. Is it posible? What library need to use? It will something like pass messages between the extension and python program.
You can try using a python interpreter implemented in javascript, like Brython for example.
Another option is to create a python web server that listens for requests with twitter ids and responds with the processed information. Your extension will then communicate with the python server same as any other api server.

How do I run python script within swift app?

I am making an app which will login to a website and scrape the website for the information I have. I currently have the all the login and web scraping written in Python completely done. What I am trying to figure out is running that python code in Xcode in my swift project. I want to avoid setting up a server capable of executing cgi scripts. Essentially the user will input their credentials and I will pass that to the python file, and the script will run.
Short answer: You don't.
There is no Python interpreter running on iOS, and Apple will likely neither provide nor allow one, since they don't allow you to deliver and run new code to in iOS app once it's installed. The code is supposed to be fixed at install time, and Python is an interpreted language.

Running a python script on my hosting

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:
I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com
I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.
Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting
The script is there below:
#! /usr/bin/python
print 'Content-type: text/html'
print ''
print 'Hello, World!
Heroku is a good place to host and python scripts.
Pre-req
pythonscripts.py
procfile
requirements.txt
and After add, commit and push the scripts to heroku app. Just run the following command on terminal to run the scripts.
heroku run python your_scripts.py
More if you want to run this scripts on a schedule timing. then heroku provides lots of adds-on. just search it on heroku
Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.
The URL would look something like this: www.domain.com/bin/mypythonscript.py
Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py
You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.
Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.
Well dream host support python. Check if they are providing shell access deployment. All you need is create .py file and run it.
Then consider to use Django or Jinja2 like framwork. Its easy for creating web application

Python scripts in HTML

Is it possible to write Python scripts in HTML code similarly as you write PHP between <?php ... ?> tags?
I'd like to achieve that my Python application will run in the browser.
thank you for help
Python indentation requirements don't go well with mixing HTML and Python code. Therefore, the most prominent method (which is a framework called Django), uses a template engine so that the Python is never in direct contact with the HTML code.
It will be similar to PHP and not javascript, as it will run on the server-side.
There is also mod_python for Apache, but I would strongly recommend using Django, which also runs on an Apache server.
PHP doesn't run in the browser, as it is a server side language. You could try Skulpt to try to run python in the browser.
You are mixing up client-side and server-side execution of code.
Browsers support only Javascript.
Any application-server or Python-based webframework support template language where you can mix HTML and Python in some way or the other.
A newer answer for an older question: There is a Python framework called Karrigell that
supports what it calls "Python Inside HTML". It interprets Python from HTML files with a ".pih" extension.
I've not tried Karrigell, but it looks compelling.
Well, this might be overkill, but you can install a localhost xampp server. Then, just put the right comments at the top of the file to direct xampp to the interpreter, and you can print out html or regular words right from the language itself. For example, a Python script like this
#!/Python34/python
print "Content-type: text/html"
print
print "Hello World"
Would give a webpage saying Hello World

Categories

Resources