I have a Django project and other python script which is a ZMQ socket which continuously listens for message to perform some operation, ZMQ server script is an independent script which for now runs as python zmq_server.py in a terminal or cmd.
What I am trying to do is start the ZMQ server script when python manage.py runserver is called to start the django server.
I did some digging but found nothing related to this, is it possible to do something like this?
You can run any script when your Django server starts by importing it in your settings.py at the top like this:
import zmq_server
Normally that's what you'd do for a script you're going to use in your project, but if you just want it to get executed you can do it like that as well.
Related
I have a Djnago web application on IIS 6 on one server. Is there a way that from this website I call another python script that is on another server in such a way that that script just run itself there?
Calling or Runnig that script in the usual way as internet says, is not working.
I always get the error of os.getcwd() and it also doesn't allow to change that directory.
I just want to run that python script there on that server from this server.
Can anyone help?
Normally, I would recommend using a framework like fabric or winrm if you want to run a python script on another server. Those frameworks use ssh or windows remoting functionality, respectively, to allow a python program to execute other commands (including python scripts) on other systems. If the target machine is a windows machine, be forewarned that you can run into all sorts of UAC issues doing normal operations.
i was going to make a simple web interface for a Python script / module I am working on. I figured to submit the form which would do 1 of 2 options. Modify a config json file and run the python script, or submit a form to the python script and execute it.
Simply put, i know when working with some other applications, Apache for example, you need to configure it such that it accepts .py files as executable. Is that the same case with SimpleHTTPServer? If so, how?
I was looking at: https://docs.python.org/2/library/simplehttpserver.html
I was also looking at BaseHTTPServer at https://docs.python.org/2/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler though nothing was jumping out at me during configuration
you can enable the CGI (Common Gateway Interface https://en.wikipedia.org/wiki/Common_Gateway_Interface ) of the SimpleHTTPServer, see the following thread How to host python cgi script with `python -m SimpleHTTPServer 8000` or `python -m CGIHTTPServer 8000`?
this is similar to get Django running ( https://en.wikipedia.org/wiki/Django_(web_framework) ) . Django is enabled using the mod_wsgi module or FastCGI on a WSGI-compatible webserver (Apache,...).
I have an installed free account on Heroku to get started.
A python code that accepts web requests is starting a shell subprocess, does starting this subprocess count and need a dyno?
I am seeing this specific code not do its intended purpose, but when run through the shell on Heroku it does what it is supposed too.
I want to run the django developement server localy and I don't want to use a full webserver.
So far I renamed manage.py to manage.pyw. Then in manage.pyw I call execute_from_command_line(['manage.py', 'runserver'])
In a batch file I then use "START pythonw manage.pyw"
The problem is, that I then cannot connect to the server even though in the taskmanager it says it's still running. When I start it using python instead, it runs, but the console window is visible.
I found a way to do this. I used the Windows Service Wrapper https://github.com/kohsuke/winsw to install python manage.py runserver as a service.
I'm developing some Python project with Django. When we render the Python/Django application, we need to open the command prompt and type in python manage.py runserver. That's ok on for the development server. But for production, it looks funny. Is there anyway to run the Python/Django project without opening the command prompt?
The deployment section of the documentation details steps to configure servers to run django in production.
runserver is to be used strictly for development and should never be used in production.
You run the runserver command only when you develop. After you deploy, the client does not need to run python manage.py runserver command. Calling the url will execute the required view. So it need not be a concern
If you are using Linux I wrote a pretty, pretty basic script, which I am always using when I don't want to call this command.
Note: You really just should use the "runserver" for developing :)
#!/bin/bash
#Of course change "IP-Address" to your current IP-Address and the "Port" to your port.
#ifconfig to get your IP-Address
python manage.py runserver IP-Address:Port
just name it runserver.sh and execute it like this in your terminal:
./runserver.sh